Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Google's webfont.js #3653

Closed
mariusbolik opened this issue Jun 21, 2019 · 6 comments
Closed

Remove Google's webfont.js #3653

mariusbolik opened this issue Jun 21, 2019 · 6 comments

Comments

@mariusbolik
Copy link

I read your statement, but the Theme Author couldn't help me.
I simply want to remove the following part in the source code of my website:

<script type="text/javascript">
/* You can add more configuration options to webfontloader by previously defining the WebFontConfig with your options */
if (typeof WebFontConfig === "undefined") {
    WebFontConfig = new Object();
}
WebFontConfig['google'] = { families: ['Open+Sans:300,400,600,700,800,300italic,400italic,600italic,700italic,800italic', 'Open+Sans+Condensed:300,700,300italic'] };

(function () {
    var wf = document.createElement('script');
    wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.5.3/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
})();
</script>

What is the best way to do that? Is there any action hook I can use? I don't want connections to google servers on my website.

Best Regards
Marius

@dovy
Copy link
Member

dovy commented Jun 21, 2019

The simplest approach is to remove all Google Fonts from your typography fields (use default fields) and it should be gone. ;)

Alternatively, you can find the author's typography fields and set a new arg as google => false.

Best of luck!

@dovy dovy closed this as completed Jun 21, 2019
@martin-braun
Copy link

martin-braun commented Jan 13, 2021

@dovy I don't really like this solution, because it will cause the stylesheets of the theme / plugin will not include the font-family declarations, anymore. It's better to do:

/**
 * Disable Google Fonts in Redux.
 */
add_action( 'redux/loaded', function( $redux ) {
	$redux->args['disable_google_fonts_link'] = true;
} );

Now the font-family definitions of the theme / plugin stylesheets won't be removed and I simply have to store the fonts and the CSS file from gstatic.com by myself and everything will work fine.

@josip-matic
Copy link

josip-matic commented Jan 28, 2021

@martin-braun Where to put this code? I broke whole site.
@mariusbolik It is not the greates solution but it is working. I contact author to add option to disable font.

@martin-braun
Copy link

@josip-matic Put it in the functions.php of your child theme.

@jmslbam
Copy link

jmslbam commented Dec 25, 2021

@martin-braun Where to put this code? I broke whole site. @mariusbolik It is not the greates solution but it is working. I contact author to add option to disable font.

It broke because the code was not complete. It forgot the ); at the end.

add_action( 'redux/loaded', function( $redux ) {
	$redux->args['disable_google_fonts_link'] = true;
});

@martin-braun
Copy link

@jmslbam Thanks, yes, copy paste failure. Edited and fixed my comment for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants