RE: Dequeue Google Fonts

I have a similar question on this. I would also like to load google fonts from my CDN (its way faster). My question is instead of disabling google fonts from the theme how do I update the source of google fonts that are used by the theme to the CDN urls? Im using icon.

@Bark201, You mean you cloned/copy the google fonts from google CDN to host it on your own CDN? I’m not sure why you need to do that since google CDN is way fast than average. I can understand if it’s a different font (not google font) but re-inventing it just for google fonts is no use. That’s because X google fonts are directly from google CDN. This is a sample code

/* cyrillic-ext */
@font-face {
  font-family: 'Open Sans';
  font-style: italic;
  font-weight: 300;
  src: local('Open Sans Light Italic'), local('OpenSans-LightItalic'), url(https://fonts.gstatic.com/s/opensans/v15/PRmiXeptR36kaC0GEAetxhgVThLs8Y7ETJzDCYFCSLE.woff2) format('woff2');
  unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}

From this

https://fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&subset=latin%2Clatin-ext&ver=4.8.2

But if you insist, you can implement the above code and remove google fonts. But there is no way you can add your own CDN URL there since the core itself is made for pre-built font system (google font and TypeKit). Hence, for you to be able to use your own custom CDN url, you’ll have to create your own custom CSS and apply them to your target elements.

Thanks.

Thank you for your reply. Google CDN is very bad from certain countries like China for example. Also in countries in South America its bad. This is why ecommerce websites that target clients on a global scale and not just Europe and US want to do it. I have a 6 seconds increase in the loading speed of the website from South American.Serving google fonts from my CDN will fix it.

If google CDN would improve then there would be no need for it. Going back to the CSS. I just need to add it to custom CSS and replace the url with the CDN? I dont need to touch functions.php right?

Do some testing on your website from China, not just one region and you will see that the page wont load in most places.

@Bark201,

Yes, you need to add it as custom CSS (in a child theme, or theme options) and you can set the CDN URL to whatever you like. You will also need to add CSS targeting the elements you want to apply that font too.

I would still recommend using this code in functions.php

add_action('init','no_google_fonts', 999999);

function no_google_fonts () {

wp_dequeue_style( 'x-google-fonts');

}

I you don’t include that, it will still load the google fonts even though they’re never used. This will slow down the page load time.

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