当前位置:K88软件开发文章中心编程语言PHPPHP01 → 文章内容

禁用google字体为你的WordPress加速

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-4 8:24:30

-->

最近很多朋友都在问为什么wordpress的打开速度非常慢,有时候需要10几秒钟才能打开,很多人都想解决这个问题,但是又不知道该如何下手,其实解决这个问题非常简单,因为wordpress默认是会加载google字体的,而且google众所周知的,在国内会被墙,所以拖慢了你网站或博客的打开速度,下面,我们就这个问题提供三种解决方法:

方法一:安装插件Disable Google Fonts或Remove Open Sans font Link from WP core等相关插件后启用插件即可,安装方法可直接在你的wordpress管理后台安装插件中搜索插件名直接安装即可!半夏推荐各位使用这种方法,简单,快捷,不会受wordpress升级或切换主题等问题的影响。

方法二:代码到当前所用的主题的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 );function wpdx_disable_open_sans( $translations, $text, $context, $domain ) { if ( ‘Open Sans font: on or off’ == $context && ‘on’ == $text ) { $translations = ‘off’; } return $translations;}

或者使用如下代码也可:

wp_deregister_style(‘open-sans’);

wp_register_style(‘open-sans’,false);

wp_enqueue_style(‘open-sans’,”);

}

add_action(‘init’,’remove_open_sans’);

方法三:Google Fonts换为360CDN,在当前的主题文件中添加如下代码即可,代码如下:

<?php/* Plugin Name: DW Replace Open Sans Plugin URI: http://devework.com/replace-open-sans.html Description: 将WordPress 后台中的open-sans字体加载源从Google Fonts替换为360的CDN加载源。 Author: Jeff Author URI: http://devework.com/ Version: 1.0 Text Domain: dw-replace-open-sans */ function devework_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’ ); wp_enqueue_style( ‘open-sans’);}add_action( ‘wp_enqueue_scripts’, ‘devework_replace_open_sans’ );add_action(‘admin_enqueue_scripts’, ‘devework_replace_open_sans’);?>

以上,自己去试试吧。

该文章由WP-AutoPost插件自动采集发布

原文地址:http://www.59iwp.com/133.html


禁用google字体为你的WordPress加速