WordPress后台打开速度慢优化教程

一、谷歌相关速度优化:

将下方相关代码添加至主题目录下functions.php中:

// 夕子小屋 xizii.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、屏蔽WordPressAPI

// 夕子小屋 xizii.com 
// 彻底关闭自动更新
add_filter('automatic_updater_disabled', '__return_true');
// 夕子小屋 xizii.com 
// 关闭更新检查定时作业
remove_action('init', 'wp_schedule_update_checks');
// 夕子小屋 xizii.com
// 移除已有的版本检查定时作业
wp_clear_scheduled_hook('wp_version_check');
// 夕子小屋 xizii.com 
// 移除已有的插件更新定时作业
wp_clear_scheduled_hook('wp_update_plugins');
// 夕子小屋 xizii.com 
// 移除已有的主题更新定时作业 
wp_clear_scheduled_hook('wp_update_themes');
// 夕子小屋 xizii.com
// 移除已有的自动更新定时作业 
wp_clear_scheduled_hook('wp_maybe_auto_update');
// 夕子小屋 xizii.com
// 移除后台内核更新检查 
remove_action( 'admin_init', '_maybe_update_core' );
// 夕子小屋 xizii.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' );
// 夕子小屋 xizii.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 字体

// 夕子小屋 xizii.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/
 
// 夕子小屋 xizii.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、移除后台界面右上角的选项

// 夕子小屋 xizii.com
// 移除后台界面右上角的选项
add_action('in_admin_header', function(){
    add_filter('screen_options_show_screen', '__return_false');
    add_filter('hidden_columns', '__return_empty_array');
});

2、移除后台界面右上角的帮助

// 夕子小屋 xizii.com
// 移除后台界面右上角的帮助
add_action('in_admin_header', function(){
    global $current_screen;
    $current_screen->remove_help_tabs();
});

3、屏蔽站点管理员邮箱验证功能

// 夕子小屋 xizii.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);

4、前台不加载语言包

// 夕子小屋 xizii.com
// 屏蔽前台语言包,提升加载速度
add_filter('locale', function($locale) {
    $locale = ( is_admin() ) ? $locale : 'en_US';
    return $locale;
});

5、删除 wp_head 中不重要的代码

// 夕子小屋 xizii.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');

6、禁用 Emoji 功能

// 夕子小屋 xizii.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' );
THE END
喜欢就支持一下吧
点赞37 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码

    暂无评论内容