WP酷 WP酷
  • 主题
  • 教程
  • 插件
  • 官方 QQ 群
  • 建站推荐
  • 联系
  • nicetheme® 奈思主题
  • 注册
    登录
立即登录
  • 请到 [后台->外观->菜单] 中设置菜单
首页 › WordPress 教程 › WordPress 解决后台速度极慢 屏蔽国外字体Google Fonts

WordPress 解决后台速度极慢 屏蔽国外字体Google Fonts

PCDotFan9年前

2014-6-2更新:近来谷歌的字体服务异常不稳定,WordPress也因为这个后台加载至少要20s。特殊时期特殊处理,刚开始以为是服务器问题,仔细分析,是载入字体的时候延时,于是就用开发者工具查看了一下,原来字体使用的是Google Fonts Open Sans,在国内访问不稳定所以会延时,解决方法很简单:

直接添加到主题的functions.php中即可禁用后台Open Sans:

//禁用Open Sans
class Disable_Google_Fonts {
        public function __construct() {
                add_filter( 'gettext_with_context', array( $this, 'disable_open_sans'             ), 888, 4 );
        }
        public function disable_open_sans( $translations, $text, $context, $domain ) {
                if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
                        $translations = 'off';
                }
                return $translations;
        }
}
$disable_google_fonts = new Disable_Google_Fonts;

 

附官方Twenty系列主题去除代码:

class Disable_Google_Fonts {
        public function __construct() {
                add_filter( 'gettext_with_context', array( $this, 'disable_open_sans'             ), 888, 4 );
                add_action( 'after_setup_theme',    array( $this, 'register_theme_fonts_disabler' ), 1      );
        }
        public function disable_open_sans( $translations, $text, $context, $domain ) {
                if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
                        $translations = 'off';
                }
                return $translations;
        }
        public function disable_lato( $translations, $text, $context, $domain ) {
                if ( 'Lato font: on or off' == $context && 'on' == $text ) {
                        $translations = 'off';
                }
                return $translations;
        }
        public function disable_source_sans_pro( $translations, $text, $context, $domain ) {
                if ( 'Source Sans Pro font: on or off' == $context && 'on' == $text ) {
                        $translations = 'off';
                }
                return $translations;
        }
        public function disable_bitter( $translations, $text, $context, $domain ) {
                if ( 'Bitter font: on or off' == $context && 'on' == $text ) {
                        $translations = 'off';
                }
                return $translations;
        }
        public function register_theme_fonts_disabler() {
                $template = get_template();
                switch ( $template ) {
                        case 'twentyfourteen' :
                                add_filter( 'gettext_with_context', array( $this, 'disable_lato'            ), 888, 4 );
                                break;
                        case 'twentythirteen' :
                                add_filter( 'gettext_with_context', array( $this, 'disable_source_sans_pro' ), 888, 4 );
                                add_filter( 'gettext_with_context', array( $this, 'disable_bitter'          ), 888, 4 );
                                break;
                }
        }
}
$disable_google_fonts = new Disable_Google_Fonts;

 

前台

使用360加速节点,将主题文件中出现的所有fonts.googleapis.com字样替换为fonts.useso.com

1
分享

本站下载管理系统「dl.mywpku.com」因年久失修而永久关闭。若需获得往年主题,请至 WP酷的百度网盘(提取码: 5rbm) 自行搜索下载。默认解压密码为「www.mywpku.com」。

对您造成的不便,敬请谅解!

PCDotFan 站长
文章 435评论 859
相关文章
  • [6.0 更新中文汉化]极度流行的SEO插件 – WordPress SEO by Yoast
  • WordPress 新用户注册邮件链接提示「您的密码重设链接无效」
  • AMP – 为 WordPress 移动站点操作全球访问优化
  • 去除谷歌服务 – WordPress 国外主题全方位加速
  • 使用 WP-CLI 简化 WordPress 操作流程
  • WordPress 基础开发 – 一探 WordPress Hook 机制及示例应用
  • 优化静态资源 – WordPress 国外主题全方位加速
  • WordPress 实现微信登录
评论 (21)
再想想
  • 跨境电商之家

    给力!不错的文章

    5年前
PCDotFan
站长
若无特别注明,则默认我发布的所有文章均为内容原创 / 翻译原创,转载时请保留来源。
435文章
859评论
3K获赞
猜你喜欢
给 WordPress 新手朋友们的建议 – 建站前必须做好的几件事
7年前
付费图床推荐 – 七牛云存储
10年前
WP External Links – 自动将外部链接添加nofollow属性
9年前
  • 杂记
  • WordPress 付费主题推荐
Copyright © 2023 WP酷. Designed by nicetheme. 琼ICP备13002067号-1