本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 [署名 4.0 国际 (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/deed.zh) 本文作者: 苏洋 创建时间: 2014年06月09日 统计字数: 1615字 阅读时间: 4分钟阅读 本文链接: https://soulteary.com/2014/06/09/replace-google-fonts.html ----- # WordPress 插件 - Open Fonts 替换 最近由于众所周知的问题,国内访问 Google Open Fonts 资源不通畅,导致主题中引用了这个资源的 WordPress 网站普遍出现了访问极其缓存的情况。 写了一个插件,使用奇虎 360 的开放字体服务来替换 Google 的开放字体服务。 如果你在使用插件过程中遇到任何问题,欢迎反馈。 ## 插件信息 > === Replace Google Fonts === > > Contributors: soulteary > > Tags: Qihu Fonts, Qihu Web Fonts, 360 Fonts, 360 Web Fonts, Google Fonts, Google Web Fonts > > Requires at least: 3.5 > > Tested up to: 3.8 > > Stable tag: 1.0 > > Use Qihoo 360 Open Fonts Service to replace Google's. > > == Description == > > [Plugin homepage](http://www.soulteary.com/2014/06/08/) | [Plugin author](http://www.soulteary.com/) > > There are some problem with Google in china, the Google Fonts make the website too slow to open, so we can use Qihoo 360's Web Fonts replace the Google's. [Project GitHub](https://github.com/soulteary/Replace-Google-Fonts). > > == Installation == > > 1\. Upload `replace-google-fonts` folder to the `/wp-content/plugins/` directory > > 2\. Activate the plugin through the 'Plugins' menu in WordPress ## 插件代码 ```php /** * Plugin Name: Replace Google Fonts * Plugin URI: http://www.soulteary.com/2014/06/08/replace-google-fonts.html * Description: Use Qihoo 360 Open Fonts Service to replace Google's. * Author: soulteary * Author URI: http://www.soulteary.com/ * Version: 1.0 * License: GPL */ /** * Silence is golden */ if (!defined('ABSPATH')) exit; class Replace_Google_Fonts { /** * init Hook * */ public function __construct() { add_filter('style_loader_tag', array($this, 'ohMyFont'), 888, 4); } /** * Use Qihoo 360 Open Fonts Service to replace Google's. * * @param $text * @return mixed */ public function ohMyFont($text) { return str_replace('//fonts.googleapis.com/', '//fonts.useso.com/', $text); } } /** * bootstrap */ new Replace_Google_Fonts; ``` 插件下载:[https://github.com/soulteary/Replace-Google-Fonts](https://github.com/soulteary/Replace-Google-Fonts)