Remove Google Fonts with functions

Hi Themeco,

How do i remove all external calls of Google Fonts? I tried this without results:

add_action(‘init’,‘no_google_fonts’, 999999);

function no_google_fonts () {
wp_dequeue_style( ‘x-font-custom’ );
wp_dequeue_style( ‘x-font-standard’ );
wp_dequeue_style( ‘x-google-fonts’);
wp_deregister_style(‘x-font-custom’);
wp_deregister_style(‘x-font-standard’);
wp_deregister_style(‘x-google-fonts’);
}

Thanks,
Menno

Hi Menno,

Thank you for writing in, this line wp_dequeue_style( 'x-google-fonts'); should exclude the x-google-fonts from loading. Add your code to child theme’s functions.php file.

If the site still loads a google font, then maybe a 3rd party plugin is requesting it and not the theme.

Cheers,

Hi @friech

It’s about this line:

href="//fonts.googleapis.com/css?family=Montserrat:300,300i,400,400i,700,700i|Open+Sans:300,300i,400,400i,700,700i&subset=latin,latin-ext" type=“text/css” media=“all” data-x-google-fonts />

I added this to the child theme functions.php but it’s not working:

add_action(‘init’,‘no_google_fonts’, 999999);

function no_google_fonts () {
wp_dequeue_style( ‘x-google-fonts’);
}

Thanks,
Menno

Hello Menno,

Please add this code in the functions.php instead:

add_filter( 'cs_load_google_fonts', '__return_false' );

#

Regarding GDPR

This release cycle introduces some minor changes to aid you in the process of staying compliant. WordPress v4.9.6 added a new privacy page feature along with a checkbox added to the comment form. We’ve added styling for this new checkbox and made sure it appears correctly in all stacks.

We’ve also made some adjustments to provide you more control over the Google Fonts loading process. To fully disable Google Fonts without custom code, you can follow these steps:

  1. Go to Theme Options → Typography
  2. Enable use of the Font Manager
  3. Click the Settings icon in the Bar and navigate to Fonts
  4. Modify each font to reference a system font instead of a Google font

After these changes are saved, no references will be made to Google Fonts on the front end of your site. Additionally, you can immediately force Google Fonts to not load by adding this code to functions.php of a child theme:

add_filter( 'cs_load_google_fonts', '__return_false' );

Finally, a new filter has been added called cs_google_fonts_uri, which can be used for advanced setups that may involve proxying Google Fonts or replicating their API.

This filter was introduced in the past updates. To read more about it, please check here:

https://theme.co/changelog/#theme-pro-2-1-0-theme-x-6-1-0-cornerstone-3-1-0

And scroll to the Regarding GPDR section.

Hope this helps.

@Jade this works!


We’ve also made some adjustments to provide you more control over the Google Fonts loading process. To fully disable Google Fonts without custom code, you can follow these steps:

  • Go to Theme Options → Typography
  • Enable use of the Font Manager
  • Click the Settings icon in the Bar and navigate to Fonts
  • Modify each font to reference a system font instead of a Google font
  • After these changes are saved, no references will be made to Google Fonts on the front end of your site. Additionally, you can immediately force Google Fonts to not load by adding this code to functions.php of a child theme:

add_filter( ‘cs_load_google_fonts’, ‘__return_false’ );


Thanks,
Menno

You’re most welcome, Menno. :slight_smile:

Hi @Jade

Any idea how to do this with the Font Awesome fonts? I would like to load a custom version of FA.

Thanks,
Menno

Hi Menno,

We currently do not have a way to fully disable FontAwesome because it is also used in the admin area such as the icons used in Cornerstone. Disabling it might cause more issue than leaving them as is that is why we strongly recommend not to dequeue the FontAwesome scripts.

However, I have added this to our Feature Request list so that it will be considered in future development.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.