禁止WordPress后台加载谷歌字体的两种方法
5.27墙改版以后,google这次挂的很彻底,chrome、gmail、adsense等全线google服务都受到很大影响。
wordpress因为使用了Google Fonts字体,后台打开需要加载数十秒,无法忍受的慢,只好干掉这项服务了。
登录Wordpress后台异常缓慢,经常卡在fonts.googleapis.com,这是由于Wordpress后台外链加载了谷歌字体(代码位置在wordpress\wp-includes\script-loader.php第580行),严重影响页面加载速度,但是不登陆的时候又是没有问题的。
那就只有把谷歌字体给禁了,访问速度恢复正常。
下面提供两种方法:
第一种方法:
将下面代码添加到主题functions.php文件中:
1 2 3 4 5 6 | function coolwp_remove_open_sans_from_wp_core() { wp_deregister_style( 'open-sans' ); wp_register_style( 'open-sans', false ); wp_enqueue_style('open-sans',''); } add_action( 'init', 'coolwp_remove_open_sans_from_wp_core' ); |
代码取自Remove Open Sans font from WP core这个插件,也可以直接安装启用该插件,这里不推荐安装插件。
第二种方法:
将下面代码添加到主题functions.php文件中:
1 2 3 4 5 6 7 8 9 10 11 12 13 | > class Disable_Google_Fonts { public function __construct() { add_filter( 'gettext_with_context', array( $this, 'disable_open_sans' ), 888, 4 ); } public function disable_open_sans( $translations, $text, $context, $domain ) { if ( 'Open Sans font: on or off' == $context && 'on' == $text ) { $translations = 'off'; } return $translations; } } $disable_google_fonts = new Disable_Google_Fonts; |
代码取自Disable-Google-Fonts这个插件,也可以直接安装启用该插件,这里不推荐安装插件。
明凯博客使用的是第一种方法,因为代码比较短。
Css中box-shadow属性实现曲线投影纸张效果 WordPress中the_title()与the_title_attribute()的区别详解
莫名其妙变慢 现在看了博文解决了
谷歌这么好的东西居然用不了。
博主你好,感谢分享