一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Google Fonts导致WordPress打开缓慢解决方法

时间:2014-06-21 编辑:简简单单 来源:一聚教程网

Google Fonts导致WordPress 速度问题之原因

WordPress 自3.8+版本后加入了Google Fonts(别问我Google Fonts是什么了),然后捏,因为近期敏感周期(35号),天朝发威,谷歌的一系列网站被彻底墙,包括Google Fonts 所在的googleapis.com 。所以,如果是在登陆状态下打开你的WordPress 站点,会非常慢,因为压根儿加载不了这个字体文件。如果是非登陆状态且你的主题不是老外的主题,一般来说都是正常的。

解决方法
出来问题就要解决,在天朝,既然你不得不忍受之,那么就换个思路变通一下。下面的解决方法,思路一是禁止加载该Google Fonts,二是替换加载源。下面说明之:

方法一:【插件】禁止WordPress 后台加载Google Fonts

安装启用 Disable Google Fonts 或者 Remove Open Sans font Link from WP core 其中之一即可。没啥好说的。

方法二:【代码】直接在functions.php 文件添加代码

网络上有不少代码,下面可以参考下,具体有没有效果没有确认:

 代码如下 复制代码
add_filter('gettext_with_context', 'disable_open_sans', 888, 4 );function disable_open_sans( $translations, $text, $context, $domain ){if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {$translations = 'off';}return $translations;}function dw_remove_open_sans() {       wp_deregister_style( 'open-sans' );          wp_register_style( 'open-sans', false );          wp_enqueue_style('open-sans','');      }  add_action( 'init', 'dw_remove_open_sans' );

方法三:【代码】替换open sans 字体的加载源

打开wordpress代码中的文件wp-includes/script-loader.php文件,搜索:fonts.googleapis.com 找到这行代码:

 代码如下 复制代码

$open_sans_font_url = "//fonts.googleapis.com/css?family1=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets";

把fonts.googleapis.com替换为fonts.useso.com。

热门栏目