微信分享缩略图
  • {{ post.title }}

    {{ post.excerpt }}

    {{ post.author_name || settings.site_author || 'Admin' }} {{ formatDate(post.published_at || post.created_at) }} {{ post.view_count }} {{ post.comment_count }}

WordPress使用谷歌字体导致访问速度很慢的解决方法

很多朋友发现最近WordPress的网站打开速度变慢了,有时候需要10几秒钟才能够打开,通过查看网站的加载情况发现原来是谷歌字体的原因,由于国内对谷歌的禁止,导致了本次WordPress整体访问速度变慢,那么我们应该如何禁用谷歌字体呢?

最简单的方法就是通过插件来实现,插件的名字Remove Open Sans font from WP core 至于插件的安装和使用就不在这里介绍。

对于不喜欢用插件的朋友,可以通过修改代码实现,代码如下 :

在主题中的functions.php文件末尾加上以下代码之一即可。此方法仅在前台有效,在后台界面无效,因为仅修改主题代码。

1. 代码一

// Remove Open Sans that WP adds from frontend
if(!function_exists('remove_wp_open_sans')):
    functionremove_wp_open_sans(){
        wp_deregister_style('open-sans');
        wp_register_style('open-sans',false);
    }
    add_action('wp_enqueue_scripts','remove_wp_open_sans');


    // Uncomment below to remove from admin
    // add_action('admin_enqueue_scripts', 'remove_wp_open_sans');
endif;

2. 代码二

    wp_deregister_style('open-sans');    
    wp_register_style('open-sans',false);    
    wp_enqueue_style('open-sans','');    
}    
add_action('init','remove_open_sans');

最后,最完美的一种 通过“移花接木”,使用360推出的国内镜像服务,来绕过GOOGLE来使用字体服务,速度也不受影响:依次打开 /wp-includes/script-loader.php,约581行的位置,搜索 “fonts.googleapis.com” 替换为 “fonts.useso.com” ,搜索“ajax.googleapis.com”替换为“ajax.useso.com”保存上传之,我们的WP程序又重新快起来了。

{{ currentPost.title }}

评论 ({{ comments.length }})

正在回复 @{{ replyTo.author_name }} 取消回复

暂无评论,来说两句吧

{{ settings.about_title || '个人简介' }}

搜索中...
没有找到相关文章
{{ r.title }}
{{ r.category_name }} {{ formatDate(r.published_at || r.created_at) }} {{ r.view_count }} 次阅读

{{ r.excerpt }}

评论通过

评论未通过

等待审核

{{ aiModalData.review || aiModalData.message }}

{{ toast.message }}