优化访问wordpress后台打开速度慢 - 【全面整理】

Wordpress打开速度太慢,这个问题一直困扰wordpress初学者。 wordpress的网站打开速度慢要怎么解决? 下面首次整理了关于wordpress后台速度提升的方法。按下面操作反应得到最大化提升。提升WordPress后台打开速度全面解决方案:

一、谷歌相关速度优化:

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

1、屏蔽谷歌字体

// 屏蔽谷歌字体
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

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

// 禁止古腾堡加载 Google 字体
add_action('admin_print_styles', function(){
    wp_deregister_style('wp-editor-font');
    wp_register_style('wp-editor-font', '');
});

4、替换 Gravatar 头像的服务器地址

名称	地址
V2EX	https://cdn.v2ex.com/gravatar/
极客族	https://sdn.geekzu.org/avatar/
loli	https://gravatar.loli.net/avatar/
inwao	https://gravatar.inwao.com/avatar/

// 替换 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、移除后台界面右上角的选项

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

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

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

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

// 屏蔽站点管理员邮箱验证功能
add_filter('admin_email_check_interval', '__return_false');

4、屏蔽站点Feed

// 屏蔽站点Feed
function wpjam_feed_disabled() {
    wp_die('Feed已经关闭, 请访问网站首页!');
}

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、前台不加载语言包

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

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

// 删除 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 功能

// 禁用 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' );

以上参考自:企业号   整理!

你可能感兴趣的:(WordPress,wordpress,wordpress加载慢,wordpress优化速度,wordpress加速,为什么wordpress那么慢)