zoukankan      html  css  js  c++  java
  • (转)关闭WordPress自动加载的Open Sans字体,总是连接googleapi.com,导致打开wordpress很慢

    转自http://www.xuanfengge.com/turn-off-automatic-loading-wordpress-open-sans-fonts.html

    一、'在网上搜了一番,有四种方法。

    (1)安装别人针对这个问题开发好的屏蔽加载谷歌字体的插件

    (2)修改过滤函数function.php

    (3)自己手动替换到加载谷歌字体的路径

    (4)使用GoAgent

    我使用了第一种方法来解决问题,

    【方法一】

    下载插件:

    1. 插件一

    名称:Remove Open Sans font Link from WP core

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

    简介:移除WP核心的谷歌字体链接.。 Installs ‘Remove Open Sans font Link from WP core’ plugin on your wordpress blog, so it will doesn’t load Open Sans font from Google fonts.

    2. 插件二

    名称:Disable Google Fonts

    地址http://wordpress.org/plugins/disable-google-fonts/

    简介:另一个类似的插件

    把这两个插件都下了。

    【方法二:functions.php过滤】

    简介

    打开主题文件夹下的functions.php文件,加上以下代码:

    【取消谷歌Open sans字体加载(更新不受影响)】

    代码1:

    add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
    function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
    if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
    $translations = 'off';
    }
    return $translations;
    }

    代码2:

    function pop_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', 'pop_remove_open_sans_from_wp_core' );

    【方法三:加载源替换】

    【Open Sans字体加载源从Google Fonts换为360 CDN】

    去除字体将导致页面字体渲染出现问题,这必然违背了网页设计者的初衷,不是很提倡。

    所以推荐使用下面替换域名的方法来解决,可以达到不改变网页原有设计、不需要修改其他代码、易于维护。

    使用替换成360 CDN加速(http://libs.useso.com/)链接的方式,不过是通过插件的形式,进行匹配,将页面所有谷歌useso.com域名的链接 替换成360提供的域名,所以不管是wordpress后台使用的字体,还是主题使用的字体、js(例如有些jquery会使用 ajax.useso.com加速),都可以实现替换输出,不需要修改代码,不需要担心程序升级更新,一劳永逸!
    代码1(推荐):
    function pop_replace_open_sans() {
    wp_deregister_style('open-sans');
    wp_register_style( 'open-sans', '//fonts.useso.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600' );
    if(is_admin()) wp_enqueue_style( 'open-sans');
    }
    add_action( 'init', 'pop_replace_open_sans' );

    代码2(下面的代码也可以搞定,不过会强制将所有的页面的googleapis.com替换成useso.com,包括文章的内容不仅仅是代码):

    function izt_cdn_callback($buffer) {return str_replace('googleapis.com', 'useso.com', $buffer);}
    function izt_buffer_start() {ob_start("izt_cdn_callback");}
    function izt_buffer_end() {ob_end_flush();}
    add_action('init', 'izt_buffer_start');
    add_action('shutdown', 'izt_buffer_end');

  • 相关阅读:
    极光推送API简易rails版本
    rake db:migrate出错
    课后作业-阅读任务-阅读提问-5
    课后作业-阅读任务-阅读提问-4
    课后作业-阅读任务-阅读提问-3
    课后作业-阅读任务-阅读提问-2
    课后作业-阅读任务-阅读提问-1
    2017012.01-构建之法:现代软件工程-阅读笔记4
    2017011.17-构建之法:现代软件工程-阅读笔记3
    20170920-构建之法:现代软件工程-阅读笔记1
  • 原文地址:https://www.cnblogs.com/wuyinghong/p/3918715.html
Copyright © 2011-2022 走看看