Hi,
My Goal: Removing all calls to Google Fonts (I only want Latin Fonts to increase site speed).
(I’ve done this in the past, but it looks like the code changed in 4.0.)
Question: How do we remove calls to Google Fonts (in order to increase site speed)?
So far, I have used theme panel to switch from Google fonts to Latin fonts.
But, when I delete lines 48-49 from functions.php:
wp_enqueue_style('google-font-rest', td_global::$http_or_https . '://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|Ubuntu:400,400italic|Open+Sans:400italic,400|Oswald:400,700|Roboto+Condensed:400italic,700italic,400,700'); //used on menus/small text
I get an error (white screen of death) when deleting these 2 lines. If I can get rid of these lines (without getting an error) I think I will have gotten rid of all the calls to Google Fonts. Can you help with the proper code?
Note: I have already deleted lines 61-84 from functions.php. (as that was the old way to remove Google Font calls).
Thanks!
~Proud User of Newspaper Theme
I posted how to do this recently, but don’t have the link, unfortunately. Perhaps do a quick forum search.
Remember, too, to search/replace the calls to Google fonts in the style.css file, too. And ensure you turn off your cache if using one, prior to making changes.
Also note some folks have trouble doing this when using child theme, if the child them css calls the fonts or a fuctions over ride file calls them.
I think you need to remove the whole section in 4.2x in functions.php which if I recall was lines 41 to 84 … you’re basically removing that “function” ….
As always, Thanks Chris. I can’t find any post that refers to the specific lines to delete (in 4.2x).
What I’m wondering is what lines we need to delete from functions.php?
I get a WSOD if I delete 48-49:
wp_enqueue_style('google-font-rest', td_global::$http_or_https . '://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|Ubuntu:400,400italic|Open+Sans:400italic,400|Oswald:400,700|Roboto+Condensed:400italic,700italic,400,700'); //used on menus/small text
Maybe this is because the speed booster is also calling Google font scripts now?
Thanks!
Hi,
okay I think in 4.2 here is what my edited functions.php looks like
lines 38 -> 59
/* ----------------------------------------------------------------------------
CSS - front end
*/
function td_load_css() {
//google fonts
if ((defined('TD_DEPLOY_MODE') and (TD_DEPLOY_MODE == 'demo' /*or TD_DEPLOY_MODE == 'dev' */)) or defined('TD_SPEED_BOOSTER')) { //on demo and dev we load only the latin fonts
//modify this collection if you want to optimize the fonts loaded
//collection url -> : http://www.google.com/fonts#ReviewPlace:refine/Collection:PT+Sans:400,700,400italic|Ubuntu:400,400italic|Open+Sans:400italic,400|Oswald:400,700|Roboto+Condensed:400italic,700italic,400,700
//wp_enqueue_style('google-font-rest', td_global::$http_or_https . '://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|Ubuntu:400,400italic|Open+Sans:400italic,400|Oswald:400,700|Roboto+Condensed:400italic,700italic,400,700'); //used on menus/small text
}
//add the google style link for fonts used by user
$td_fonts_css_files = td_util::get_option('td_fonts_css_files');
if(!empty($td_fonts_css_files)) {
wp_enqueue_style('google-fonts-style', td_global::$http_or_https . $td_fonts_css_files);
}
//bootstrap - custom built - it was generated via compilation of /external/bootstrap-master/less/bootstrap.less
You will note I didn’t remove 44-49, I commented it out with //
I did not remove the code which is there *if* somebody selects fonts from the admin panel, which I think is what you were doing; and then it would crash.
And I DELETED this
$td_user_fonts_list = array();
$td_user_fonts_db = td_util::get_option('td_fonts');
if(!empty($td_user_fonts_db)) {
foreach($td_user_fonts_db as $td_font_setting_key => $td_font_setting_val) {
if(!empty($td_font_setting_val) and !empty($td_font_setting_val['font_family'])) {
$td_user_fonts_list[] = $td_font_setting_val['font_family'];
}
}
}
if(!in_array('g_438', $td_user_fonts_list)) {//'g_438', //Open Sans
wp_enqueue_style('google-font-opensans', td_global::$http_or_https . '://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic'); //used on menus/small text
}
if(!in_array('g_617', $td_user_fonts_list)) {//'g_617', //Ubuntu
wp_enqueue_style('google-font-ubuntu', td_global::$http_or_https . '://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic&subset=latin,cyrillic-ext,greek-ext,greek,latin-ext,cyrillic'); //used on content
}
if(!in_array('g_453', $td_user_fonts_list)) {//'g_453', //PT Sans
wp_enqueue_style('google-font-pt-sans', td_global::$http_or_https . '://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic&subset=latin,cyrillic-ext,latin-ext,cyrillic'); //used on content
}
if(!in_array('g_445', $td_user_fonts_list)) {//'g_445', //Oswald
wp_enqueue_style('google-font-oswald', td_global::$http_or_https . '://fonts.googleapis.com/css?family=Oswald:400,300,700&subset=latin,latin-ext'); //used on content
}
if(!in_array('g_521', $td_user_fonts_list)) {//'g_521', //Roboto
wp_enqueue_style('google-roboto-cond', td_global::$http_or_https . '://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,400italic,700italic,400,300,700&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic'); //used on content
}
if(!in_array('g_639', $td_user_fonts_list)) {//'g_639', //Vollkorn
wp_enqueue_style('google-vollkorn', td_global::$http_or_https . '://fonts.googleapis.com/css?family=Vollkorn:400italic,700italic,400,700'); //used on quoates classic
}
}
-
This reply was modified 11 years by
simchris.
Chris,
It works!
That got rid of those nasty .woff files that take forever to load. Page speed of my site improved by 40%.
(Still trying to figure out where the fonts.googleapis.com call is coming from. Looks like a Roboto text is still lurking somewhere?).
That code fix is great! Thanks again.
You’re welcome 🙂
I cc’d that over to the page speed sticky, since I realized bunches of things I’ve answered more than once were NOT actually in that sticky!
One of these days I’ll do an updated “ONE POST” with all my fixes, but in midst of doing the migration to mod_SPDY for the server which is pain in the butt.