解决WordPress后台加载字体慢的方法

2014年6 月11日 / 网站源码 / 没有评论 / 805次

最近很多人说,WordPress后台加载字体很慢,原因是加载了google的字体,而Google会出现经常打不开或者访问速度过慢的情况,所以会拖延站点的打开速度。观察发现script-loader.php(wp-3.9)的580行代码进行加载。
那么我们怎么解决呢?
在主题中的functions.php文件末尾加上

  1. add_action('wp_loaded', 'wp_disable_google_fonts');
  2.  function wp_disable_google_fonts() {ob_start('wp_disable_google_fonts_regex');}
  3. function wp_disable_google_fonts_regex($html) {$html = preg_replace('/<link[^<>]*\/\/fonts\.(googleapis|google|gstatic)\.com[^<>]*>/i', '', $html);return $html;}

插件过滤移除WP核心的谷歌字体链接.地址:http://wordpress.org/plugins/remove-open-sans-font-from-wp-core/