介绍
WordPress打开速度太慢,这个问题一直困扰wordpress初学者。 wordpress的网站打开速度慢要怎么解决? 下面首次整理了关于wordpress后台速度提升的方法。按下面操作反应得到最大化提升。提升WordPress后台打开速度全面解决方案:
一、谷歌相关速度优化:
将下方相关代码添加至主题目录下functions.php中:
1、屏蔽谷歌字体
// 泽楠云博客 https://iizny.com
// 屏蔽谷歌字体
add_filter( 'gettext_with_context', 'wpjam_disable_google_fonts', 888, 4);
function wpjam_disable_google_fonts($translations, $text, $context, $domain ) {
$google_fonts_contexts = array('Open Sans font: on or off','Lato font: on or off','Source Sans Pro font: on or off','Bitter font: on or off');
if( $text == 'on' && in_array($context, $google_fonts_contexts ) ){
$translations = 'off';
}
return $translations;
}
2、屏蔽wordpress的API
// 泽楠云博客 https://iizny.com
// 彻底关闭自动更新
add_filter('automatic_updater_disabled', '__return_true');
// 泽楠云博客 https://iizny.com
// 关闭更新检查定时作业
remove_action('init', 'wp_schedule_update_checks');
// 泽楠云博客 https://iizny.com
// 移除已有的版本检查定时作业
wp_clear_scheduled_hook('wp_version_check');
// 泽楠云博客 https://iizny.com
// 移除已有的插件更新定时作业
wp_clear_scheduled_hook('wp_update_plugins');
// 泽楠云博客 https://iizny.com
// 移除已有的主题更新定时作业
wp_clear_scheduled_hook('wp_update_themes');
// 泽楠云博客 https://iizny.com
// 移除已有的自动更新定时作业
wp_clear_scheduled_hook('wp_maybe_auto_update');
// 泽楠云博客 https://iizny.com
// 移除后台内核更新检查
remove_action( 'admin_init', '_maybe_update_core' );
// 泽楠云博客 https://iizny.com
// 移除后台插件更新检查
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
// 泽楠云博客 https://iizny.com
// 移除后台主题更新检查
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'load-update-core.php', 'wp_update_themes' );
remove_action( 'admin_init', '_maybe_update_themes' );
3、禁止古腾堡加载 Google 字体
// 泽楠云博客 https://iizny.com
// 禁止古腾堡加载 Google 字体
add_action('admin_print_styles', function(){
wp_deregister_style('wp-editor-font');
wp_register_style('wp-editor-font', '');
});
替换 Gravatar 头像的服务器地址
名称 地址
V2EX https://cdn.v2ex.com/gravatar/
极客族 https://sdn.geekzu.org/avatar/
loli https://gravatar.loli.net/avatar/
inwao https://gravatar.inwao.com/avatar/
// 泽楠云博客 https://iizny.com
// 替换 Gravatar 头像的服务器地址
function mytheme_get_avatar( $avatar ) {
$avatar = preg_replace( "/http://(www|d).gravatar.com/","替换地址",$avatar );
return $avatar;
} add_filter( 'get_avatar', 'mytheme_get_avatar' );
二、其他相关速度提升优化:
1、移除后台界面右上角的选项
// 泽楠云博客 https://iizny.com
// 移除后台界面右上角的选项
add_action('in_admin_header', function(){
add_filter('screen_options_show_screen', '__return_false');
add_filter('hidden_columns', '__return_empty_array');
});
2、移除后台界面右上角的帮助
// 泽楠云博客 https://iizny.com
// 移除后台界面右上角的帮助
add_action('in_admin_header', function(){
global $current_screen;
$current_screen->remove_help_tabs();
});
3、屏蔽站点管理员邮箱验证功能
// 泽楠云博客 https://iizny.com
// 屏蔽站点Feed
function wpjam_feed_disabled() {
wp_die('Feed已经关闭, 请访问网站<a href="'.get_bloginfo('url').'">首页</a>!');
}
add_action('do_feed', 'wpjam_feed_disabled', 1);
add_action('do_feed_rdf', 'wpjam_feed_disabled', 1);
add_action('do_feed_rss', 'wpjam_feed_disabled', 1);
add_action('do_feed_rss2', 'wpjam_feed_disabled', 1);
add_action('do_feed_atom', 'wpjam_feed_disabled', 1);
5、前台不加载语言包
// 泽楠云博客 https://iizny.com
// 屏蔽前台语言包,提升加载速度
add_filter('locale', function($locale) {
$locale = ( is_admin() ) ? $locale : 'en_US';
return $locale;
});
6、删除 wp_head 中不重要的代码
// 泽楠云博客 https://iizny.com
// 删除 wp_head 中不重要的代码
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
7、禁用 Emoji 功能
// 泽楠云博客 https://iizny.com
// 禁用 Emoji 功能
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('embed_head', 'print_emoji_detection_script');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
add_filter( 'emoji_svg_url', '__return_false' );
温馨提示:
© 版权声明
本站网络名称:
泽楠云资源博客
本站永久网址:
https://iizny.com
网站侵权说明:
本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长QQ905730354删除处理。
1 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
2 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
3 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
1 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
2 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
3 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
THE END
喜欢就支持一下吧
gyh494979154N新朋友1小时前0
666666666彬彬有礼游客7小时前0
感谢分享,感谢感谢godyuN新朋友前天0
嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻godyuN新朋友前天0
惺惺惜惺惺啊gyh494979154N新朋友前天0
666666gyh494979154N新朋友前天0
666666pitifanN新朋友2天前0
可乐游客2天前0
哈哈哈哈好好好好好好