禁用 Google Fonts,加快 WordPress 后台打开速度

张子凡 WordPress优化 2014-06-05 15:00:49 阅读(...) 评论(2)

最近 Google 又非常慢,并且有时无法打开,而 WordPress 后台又使用了 Google 字体,导致 WordPress 加载非常慢,所以我们需要在 WordPress 中禁用 Google Fonts,将下面的代码铁入到当前主题的 functions.php 文件:

1
2
3
4
5
6
7
8
9
//禁用 Google Fonts
function fanly_disable_google_fonts($translations, $text, $context, $domain ) {
	$google_fonts_contexts = array('Open Sans font: on or off','Lato font: on or off','Source Sans Pro font: on or off','Bitter font: on or off');
	if( $text == 'on' && in_array($context, $google_fonts_contexts ) ){
		$translations = 'off';
	}
 
	return $translations;
}

最近又发现一个新方式,顺便贴出来吧!

1
2
3
4
5
6
7
//禁用 Google Fonts
function remove_open_sans() {    
    wp_deregister_style( 'open-sans' );    
    wp_register_style( 'open-sans', false );    
    wp_enqueue_style('open-sans','');    
}    
add_action( 'init', 'remove_open_sans' );

两种方法大家选其一就好了!

更多关于WordPress优化及疑问可以添加QQ群:255308000

除非注明,否则均为泪雪博客原创文章,禁止任何形式转载

本文链接:https://zhangzifan.com/disable-google-fonts.html

留言评论

登录 后留言