解决WordPress后台打开慢问题:删除替换谷歌字体

引言:此文由子域名转移而来,因为细微强迫症和放弃子域名而不舍得完全丢弃,所以将会逐步第二次转移文章到主域名上来,二者主题(阿里白秀和D8)均来自大前端,追求完美的同时有一丝小懒,主题就不换了,D8主题用起来挺好。

/tmp/phpa3jOhn

最近几天网络上频频出现异常情况:比如google网站打不开或访问过慢、百度搜索页面格式错误、关键是算我在内,所有人在登录的wordpress后台时十分缓慢,时不时就出现白屏的情况,这和google网站打不开有关系么?通过查找原因发现,原来wordpress登录后台时加载了google字体,难怪会影响到了wordpress。所以我们可以这样修改:

(此文章最新修改于2014年6月28日)

方法一:

①在function.php中添加如下代码:

  1. if (!function_exists('remove_wp_open_sans')) :
  2.     //移除wp后台加载字体
  3.     function remove_wp_open_sans() {
  4.         wp_deregister_style( 'open-sans' );
  5.         wp_register_style( 'open-sans', false );
  6.         wp_enqueue_style('open-sans','');
  7.     }
  8.     // 前台删除Google字体CSS
  9.     add_action('wp_enqueue_scripts', 'remove_wp_open_sans');
  10.     // 后台删除Google字体CSS
  11.     add_action('admin_enqueue_scripts', 'remove_wp_open_sans');
  12. endif;

②或下载移除WP核心的谷歌字体链接插件:remove-open-sans-font-from-wp-core

​​http://wordpress.org/plugins/remove-open-sans-font-from-wp-core/

方法二:

该方法是采用360 CDN替换google字体,但这种方法会把所有链接替换,而且采用插件的形式,对于普通用户来说很是方便。

①插件名称:googleapis to useso

百度网盘下载
千脑网盘下载

②如果不想用插件,可以使用代码方式:

  1. //用360 cdn替换google链接
  2. function izt_cdn_callback($buffer) {return str_replace('useso.com', 'useso.com', $buffer);}
  3. function izt_buffer_start() {ob_start("izt_cdn_callback");}
  4. function izt_buffer_end() {ob_end_flush();}
  5. add_action('init', 'izt_buffer_start');
  6. add_action('shutdown', 'izt_buffer_end');

方法三:目前使用此方法,它屏蔽了google的Google Fonts Open Sans字体,但是效果不是很管用,登录到后台还是很慢,如果有大神指点一二,感激不尽……

  1. class Disable_Google_Fonts {
  2.     public function __construct() {
  3.         add_filter( 'gettext_with_context', array( $this, 'disable_open_sans' ), 8884 );
  4.     }
  5.     public function disable_open_sans( $translations, $text, $context, $domain ) {
  6.         if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
  7.             $translations = 'off';
  8.         }
  9.         return $translations;
  10.     }
  11. }
  12. $disable_google_fonts = new Disable_Google_Fonts;

以上三种方法选择其一即可,赶快加上吧,Let's go!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注