利用纯代码来禁用谷歌字体加速网站的响应速度-解决谷歌字体无法加载

阿里云2折

利用纯代码来禁用谷歌字体加速网站的响应速度-解决谷歌字体无法加载

WordPress 加载谷歌字体的代码在于 wordpress\wp-includes\script-loader.php 文件里面,这里展示三个代码.

wordpress解决后台打开慢代码屏蔽加载谷歌字体,首先我们想到的是为什么wordpress后台打开速度很慢,其实有俩个原因一个是谷歌加载字体和Gravatar头像被墙的原因带来的

// WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source.
$scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' );
$scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array( 'prototype' ), '1.9.0' );
$scripts->add( 'scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array( 'scriptaculous-builder', 'scriptaculous-effects' ), '1.9.0' );
$scripts->add( 'scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array( 'scriptaculous-effects' ), '1.9.0' );
$scripts->add( 'scriptaculous-sound', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) );
// Hotlink Open Sans, for now
$open_sans_font_url = "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets";
/*
 * Translators: Use this to specify the proper Google Font name and variants
 * to load that is supported by your language. Do not translate.
 * Set to 'off' to disable loading.
 */
$font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants' );
if ( 'off' !== $font_family ) {
    $fonts_url = 'https://fonts.googleapis.com/css?family=' . urlencode( $font_family );
}

由于代码实在太多了,这里只截取了重要语句,具体大家想话可以直接在该文件下查找。

然后是禁用代码,直接将下面代码添加到主题的 functions.php 文件中即可。

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

第二就是解决掉Gravatar头像国内访问不了的问题

add_filter(‘get_avatar’, ‘wuzhuti_get_avatar’, 10, 3);
function wuzhuti_get_avatar($avatar) {
$avatar = str_replace(array(‘www.gravatar.com’, ‘0.gravatar.com’, ‘1.gravatar.com’, ‘2.gravatar.com’), ‘gravatar.duoshuo.com’, $avatar);
return $avatar;
}

把以上代码直接复制到functions.php模板当中就能解决上述问题,

卓越源码阁版权申明

1、本网站采用BY-NC-SA协议进行授权资源,仅限于学习研究!
2、本站资源多为网络收集,我们不承担任何技术及版权问题,严禁从事商业或者非法活动!
3、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予以删除并致以最深的歉意!
4、侵权删帖/违法举报/投稿等事物联系邮箱:zuoyueyuanma@qq.com!

分享到:
赞(1) 打赏

评论抢沙发

评论前必须登录!

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏