优化访问wordpress后台打开速度慢 – 【全面整理】2年前发布0370 介绍 WordPress打开速度太慢,这个问题一直困扰wordpress初学者。 wordpress的网站打开速度慢要怎么解决? 下面首次整理了关于wordpress后台速度提升的方法。按下面操作反应得到最大化提升。提升WordPress后台打开速度全面解决方案: 一、谷歌相关速度优化: 将下方相关代码添加至主题目录下functions.php中: 1、屏蔽谷歌字体 // 优知新博客 https://uzhix.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://uzhix.com // 彻底关闭自动更新add_filter('automatic_updater_disabled', '__return_true');// 优知新博客 https://uzhix.com// 关闭更新检查定时作业remove_action('init', 'wp_schedule_update_checks');// 优知新博客 https://uzhix.com // 移除已有的版本检查定时作业wp_clear_scheduled_hook('wp_version_check');// 优知新博客 https://uzhix.com // 移除已有的插件更新定时作业wp_clear_scheduled_hook('wp_update_plugins');// 优知新博客 https://uzhix.com // 移除已有的主题更新定时作业 wp_clear_scheduled_hook('wp_update_themes');// 优知新博客 https://uzhix.com// 移除已有的自动更新定时作业 wp_clear_scheduled_hook('wp_maybe_auto_update');// 优知新博客 https://uzhix.com // 移除后台内核更新检查 remove_action( 'admin_init', '_maybe_update_core' );// 优知新博客 https://uzhix.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://uzhix.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://uzhix.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://uzhix.com // 移除后台界面右上角的选项add_action('in_admin_header', function(){ add_filter('screen_options_show_screen', '__return_false'); add_filter('hidden_columns', '__return_empty_array');}); 2、移除后台界面右上角的帮助 // 优知新博客 https://uzhix.com // 移除后台界面右上角的帮助add_action('in_admin_header', function(){ global $current_screen; $current_screen->remove_help_tabs();}); 3、屏蔽站点管理员邮箱验证功能 // 优知新博客 https://uzhix.com // 屏蔽站点Feedfunction 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://uzhix.com // 屏蔽前台语言包,提升加载速度add_filter('locale', function($locale) { $locale = ( is_admin() ) ? $locale : 'en_US'; return $locale;}); 6、删除 wp_head 中不重要的代码 // 优知新博客 https://uzhix.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://uzhix.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' ); 温馨提示:本文最后更新于2023-06-23 00:13:46,某些文章具有时效性,若有错误或已失效,请私信客服或联系知新社长。 © 版权声明文章版权归作者所有,未经允许请勿转载。 六月 23 知岛上的今时往日 2024:海狸浮生记/Timberborn (0)2024:帝国:希腊战争/Imperiums: Greek Wars (0)2024:致命广播/Deadly Broadcast (0)2024:艾拉贡/Iragon (0)2024:在时间之间:逃离室/Between Time: Escape Room (0) THE END网站/配置/代码# 优化 喜欢就支持一下吧点赞0 分享QQ空间微博QQ好友海报分享复制链接收藏