[历史归档]本文原发布于 cstriker1407.info 个人博客,内容为历史存档,仅供参考。
发布时间:2015-01-29| 标题:【转】WordPress 后台禁用Google Open Sans字体,加速网站|分类:编程 / vps && wordpress / web |标签:vps && wordpress
【转】WordPress 后台禁用Google Open Sans字体,加速网站
- 修改方式:
- 更改为360:
- 通过插件禁用:
- Remove Open Sans font Link from WP core
以下内容转自【 <www.izhangheng.com/replace-googleapi-fonts> 】,有删改。
之前用 Google 的时候就发现无法打开,也没多想,原来从5月27日开始,Google的部分服务开始被屏蔽,其中最主要的是HTTPS搜索服务和Google登录服务,所有版本的Google都受到影响,包括google.hk和google.com等。
这次是 Google 被封时间最长、服务最多的一次,严重影响到我正常使用互联网、相册、网盘、Nexus手机等,TNND。
对于 WordPress 站长来说,也会受到不小的影响,尤其是无法加载 fonts.googleapi.com 的字体,会造成博客打开特别慢,严重的甚至无法打开。
修改方式:
更改为360:
打开 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";改为:
$open_sans_font_url="//fonts.useso.com/css?family1=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets";实际上就是将 fonts.googleapis.com 替换为 fonts.useso.com,保存后再重新上传到博客空间上,刷新页面就能看到效果了。
大家就可以发现,自己的网站速度已经比以前快了很多,几乎瞬间就可以拿到 Google 字体了,原因就是本来需要从美国服务器才能拿到的 Google 字体,现在已经遍布360全国的机房了。
通过插件禁用:
转自【 <www.wpdaxue.com/disable-google-fonts.html> 】,有删改。
安装启用Disable Google Fonts或者Remove Open Sans font Link from WP core其中之一即可。或者如果你没有使用WP自带的官方主题,那你添加下面的代码到当前所用的主题的 functions.php 中即可:
/** * WordPress 后台禁用Google Open Sans字体,加速网站 * http://www.wpdaxue.com/disable-google-fonts.html */add_filter('gettext_with_context','wpdx_disable_open_sans',888,4);functionwpdx_disable_open_sans($translations,$text,$context,$domain){if('Open Sans font: on or off'==$context&&'on'==$text){$translations='off';}return$translations;}Remove Open Sans font Link from WP core
作者这里用的是Remove Open Sans font Link from WP core 这个插件,这里贴下它的代码,仅供参考。
<?php/* Plugin Name: Remove Open Sans font from WP core Plugin URI: http://suoling.net/remove-open-sans-font-from-wp-core/ Description: Remove Open Sans font from WP core. Version: 1.2.1 Author: suifengtec Author URI: http://suoling.net License: GPL v2 or later */defined('ABSPATH')orexit;functioncoolwp_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');/* thanks Milan Dinić. */add_filter('gettext_with_context','coolwp_disable_open_sans',888,4);functioncoolwp_disable_open_sans($translations,$text,$context,$domain){if(('Open Sans font: on or off'==$context&&'on'==$text)/*for twentyfourteen*/||('Lato font: on or off'==$context&&'on'==$text)/*for twentyfifteen*/||('Noto Sans font: on or off'==$context&&'on'==$text)||('Noto Serif font: on or off'==$context&&'on'==$text)||('Inconsolata font: on or off'==$context&&'on'==$text)){$translations='off';}return$translations;}?>