WordPress网站前后台加载速度非常慢,屏蔽谷歌字体+WPJAM BASIC插件解决

2023-02-0910:16:17网站管理维护Comments1,337 views字数 6072阅读模式

WordPress网站卡顿加载慢的原因:

众所周知WordPress建站系统服务器是在国外,当用户在国内访问国外的资源时,访问页面速度必然会下降很多,比如谷歌字体,后台系统自带的图片、缓存、API、等等之类因素都会影响页面加载速度。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

解决办法一、(使用代码实现加速)

复制下面禁用谷歌字体代码放入到主题文件下的functions.php下面,注意是需要放在<?php 代码下面(修改之前建议先备份文件,以免发生意外的错误。)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

// 屏蔽谷歌字体
add_filter( 'gettext_with_context'<span%20class="enlighter-text">, 'wpjam_disable_google_fonts'<span%20class="enlighter-text">, 888, 4);
function wpjam_disable_google_fonts($translations, $text, $context, $domain ) {
$google_fonts_contexts = array('Open Sans font: on or off'<span%20class="enlighter-text">,'Lato font: on or off'<span%20class="enlighter-text">,'Source Sans Pro font: on or off'<span%20class="enlighter-text">,'Bitter font: on or off'<span%20class="enlighter-g1">);
if( $text == 'on' && in_array($context, $google_fonts_contexts ) ){
$translations = 'off'<span%20class="enlighter-text">;
}
return $translations;
}
// 禁止古腾堡加载 Google 字体
add_action('admin_print_styles'<span%20class="enlighter-text">, function(){wp_deregister_style('wp-editor-font'<span%20class="enlighter-g1">);wp_register_style('wp-editor-font'<span%20class="enlighter-text">, ''<span%20class="enlighter-g1">);});

下面是其他一些禁用加载的代码,根据个人需求选择性使用,每个代码之前都有备注含义,同样是放入到主题文件下的functions.php下面文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

// 彻底关闭自动更新
add_filter('automatic_updater_disabled'<span%20class="enlighter-text">, '__return_true'<span%20class="enlighter-g1">);
// 关闭更新检查定时作业
remove_action('init'<span%20class="enlighter-text">, 'wp_schedule_update_checks'<span%20class="enlighter-g1">);
// 移除已有的版本检查定时作业
wp_clear_scheduled_hook('wp_version_check'<span%20class="enlighter-g1">);
// 移除已有的插件更新定时作业
wp_clear_scheduled_hook('wp_update_plugins'<span%20class="enlighter-g1">);
// 移除已有的主题更新定时作业
wp_clear_scheduled_hook('wp_update_themes'<span%20class="enlighter-g1">);
// 移除已有的自动更新定时作业
wp_clear_scheduled_hook('wp_maybe_auto_update'<span%20class="enlighter-g1">);
// 移除后台内核更新检查
remove_action( 'admin_init'<span%20class="enlighter-text">, '_maybe_update_core' );
// 移除后台插件更新检查
remove_action( 'load-plugins.php'<span%20class="enlighter-text">, 'wp_update_plugins' );
remove_action( 'load-update.php'<span%20class="enlighter-text">, 'wp_update_plugins' );
remove_action( 'load-update-core.php'<span%20class="enlighter-text">, 'wp_update_plugins' );
remove_action( 'admin_init'<span%20class="enlighter-text">, '_maybe_update_plugins' );
// 移除后台主题更新检查
remove_action( 'load-themes.php'<span%20class="enlighter-text">, 'wp_update_themes' );
remove_action( 'load-update.php'<span%20class="enlighter-text">, 'wp_update_themes' );
remove_action( 'load-update-core.php'<span%20class="enlighter-text">, 'wp_update_themes' );
remove_action( 'admin_init'<span%20class="enlighter-text">, '_maybe_update_themes' );
// 替换 Gravatar 头像的服务器地址
function mytheme_get_avatar( $avatar ) {
$avatar = preg_replace( "/http://(www|d).gravatar.com/","替换地址",$avatar );
return $avatar;
} add_filter( 'get_avatar'<span%20class="enlighter-text">, 'mytheme_get_avatar' );
// 移除后台界面右上角的选项
add_action('in_admin_header'<span%20class="enlighter-text">, function(){
add_filter('screen_options_show_screen'<span%20class="enlighter-text">, '__return_false'<span%20class="enlighter-g1">);
add_filter('hidden_columns'<span%20class="enlighter-text">, '__return_empty_array'<span%20class="enlighter-g1">);
});// 移除后台界面右上角的帮助
add_action('in_admin_header'<span%20class="enlighter-text">, function(){
// 屏蔽站点管理员邮箱验证功能
add_filter('admin_email_check_interval'<span%20class="enlighter-text">, '__return_false'<span%20class="enlighter-g1">);
// 屏蔽站点Feed
function wpjam_feed_disabled() {
wp_die('Feed已经关闭, 请访问网站<a href="'<span%20class="enlighter-text">.get_bloginfo('url'<span%20class="enlighter-g1">).'">首页</a>!'<span%20class="enlighter-g1">);
}
add_action('do_feed'<span%20class="enlighter-text">, 'wpjam_feed_disabled'<span%20class="enlighter-text">, 1);
add_action('do_feed_rdf'<span%20class="enlighter-text">, 'wpjam_feed_disabled'<span%20class="enlighter-text">, 1);
add_action('do_feed_rss'<span%20class="enlighter-text">, 'wpjam_feed_disabled'<span%20class="enlighter-text">, 1);
add_action('do_feed_rss2'<span%20class="enlighter-text">, 'wpjam_feed_disabled'<span%20class="enlighter-text">, 1);
add_action('do_feed_atom'<span%20class="enlighter-text">, 'wpjam_feed_disabled'<span%20class="enlighter-text">, 1);
// 屏蔽前台语言包,提升加载速度
add_filter('locale'<span%20class="enlighter-text">, function($locale) {
$locale = ( is_admin() ) ? $locale : 'en_US'<span%20class="enlighter-text">;
return $locale;
});
// 删除 wp_head 中不重要的代码
remove_action('wp_head'<span%20class="enlighter-text">, 'rsd_link'<span%20class="enlighter-g1">);
remove_action('wp_head'<span%20class="enlighter-text">, 'wlwmanifest_link'<span%20class="enlighter-g1">);
remove_action('wp_head'<span%20class="enlighter-text">, 'wp_generator'<span%20class="enlighter-g1">);
remove_action('wp_head'<span%20class="enlighter-text">, 'start_post_rel_link'<span%20class="enlighter-g1">);
remove_action('wp_head'<span%20class="enlighter-text">, 'index_rel_link'<span%20class="enlighter-g1">);
remove_action('wp_head'<span%20class="enlighter-text">, 'adjacent_posts_rel_link'<span%20class="enlighter-g1">);
// 禁用 Emoji 表情符合功能
remove_action('admin_print_scripts'<span%20class="enlighter-text">, 'print_emoji_detection_script'<span%20class="enlighter-g1">);
remove_action('admin_print_styles'<span%20class="enlighter-text">, 'print_emoji_styles'<span%20class="enlighter-g1">);
remove_action('wp_head'<span%20class="enlighter-text">, 'print_emoji_detection_script'<span%20class="enlighter-text">, 7);
remove_action('wp_print_styles'<span%20class="enlighter-text">, 'print_emoji_styles'<span%20class="enlighter-g1">);
remove_action('embed_head'<span%20class="enlighter-text">, 'print_emoji_detection_script'<span%20class="enlighter-g1">);
remove_filter('the_content_feed'<span%20class="enlighter-text">, 'wp_staticize_emoji'<span%20class="enlighter-g1">);
remove_filter('comment_text_rss'<span%20class="enlighter-text">, 'wp_staticize_emoji'<span%20class="enlighter-g1">);
remove_filter('wp_mail'<span%20class="enlighter-text">, 'wp_staticize_emoji_for_email'<span%20class="enlighter-g1">);
add_filter( 'emoji_svg_url'<span%20class="enlighter-text">, '__return_false' );

解决办法二、(如果不会代码的情况,利用WPJAM BASIC插件实现加速)

1.后台插件库中搜索:WPJAM BASIC 并且安装。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

WordPress网站前后台加载速度非常慢,屏蔽谷歌字体+WPJAM BASIC插件解决文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

2.后台设置根据个人需求设置勾选需要禁用的选项,保存即可实现WordPress网站加速。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

WordPress网站前后台加载速度非常慢,屏蔽谷歌字体+WPJAM BASIC插件解决文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

总结:

使用了以上任意一种WordPress网站优化加速方法以后,会感觉到网站明显速度有所提升,前提是需要保证你网站架设的服务器也能正常流畅运行。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

另外提供一个让网站提速2-5倍,快的起飞的方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/wg/30776.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/wg/30776.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定