Warning: Illegal string offset 'top' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 45

最近发现登录Wordpress后台异常缓慢,经常卡在fonts.googleapis.com,这是由于Wordpress后台外链加载了谷歌字体(代码位置在wordpress\wp-includes\script-loader.php第580行),而谷歌服务器大家都知道的原因国内访问困难,严重影响页面加载速度。

 

解决办法:

将下面代码添加到主题functions.php文件中:

  1. function coolwp_remove_open_sans_from_wp_core() {

  2.     wp_deregister_style( 'open-sans' );

  3.     wp_register_style( 'open-sans', false );

  4.     wp_enqueue_style('open-sans','');

  5. }

  6. add_action( 'init', 'coolwp_remove_open_sans_from_wp_core' );

之后,再次登录后台速度明显提升。

代码取自 Remove  Open Sans font from WP core 插件,也可以直接安装启用该插件。

相似功能的插件:Disable Google Fonts

因Google字库中只有英文,对国人无任何用处,换用国内某字体服务的方法同样意义不大,禁掉最实用。

上述方法对前台主题加载Google字体无效,国外主题也多采用外链Google字体,自行手动修改模板删除相关代码。

以Wordpress默认主题Twenty Fourteen为例,打开主题functions.php模板文件,查找并删除:

  1. //fonts.googleapis.com/css

其它主题类似,但可能不在functions.php模板中,只能逐一文件查找,只搜索google关键字就可以了。

注:这已是目前国内使用Wordpress所必须做的,建议国内主题设计者直接集成在主题中,不然刚接触WP的新手,会因此放弃,瓷瓶国又一悲剧!


Warning: Illegal string offset 'footer' in /www/wwwroot/hellyhua.com/wp-content/themes/Snape/single.php on line 49