卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章11201本站已运行3223

WordPress v5.8.1必备优化方法

优化代码添加至主题目录functions.php文件,全盘停用自动更新(核心程序/主题/插件/译者自动更新

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' );

/*关闭程序更新提示信息*/

add_filter( 'pre_site_transient_update_core', function($a){ return null; });

/*停用插件更新提示*/

add_filter('pre_site_transient_update_plugins', function($a){return null;});

/*关闭主题更新提示信息*/

add_filter('pre_site_transient_update_themes', function($a){return null;});

//关闭WordPress的XML-RPC功能

add_filter('xmlrpc_enabled', '__return_false');

//停用XML-RPC的 pingback端口

add_filter( 'xmlrpc_methods', 'remove_xmlrpc_pingback_ping' );
function remove_xmlrpc_pingback_ping( $methods ) {
unset( $methods['pingback.ping'] );
return $methods;
}

//去除前端网页源代码内的头部冗余代码

remove_action( 'wp_head', 'feed_links_extra', 3 ); 
remove_action( 'wp_head', 'rsd_link' ); 
remove_action( 'wp_head', 'wlwmanifest_link' ); 
remove_action( 'wp_head', 'index_rel_link' ); 
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); 
remove_action( 'wp_head', 'wp_generator' );

//移除新版本站点健康状态面板和菜单项

add_action( 'admin_menu', 'remove_site_health_menu' ); 
function remove_site_health_menu(){
remove_submenu_page( 'tools.php','site-health.php' ); 
}

//停止使用5.5版后自带的XML站点地图

add_filter( 'wp_sitemaps_enabled', '__return_false' );

//移除后台仪表盘站点身心健康状态面板

add_action('wp_dashboard_setup', 'remove_site_health_dashboard_widget');
function remove_site_health_dashboard_widget()
{
remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
}

//去除后台仪表盘菜单:站点健康状态

add_action( 'admin_menu', 'remove_site_health_menu' );
function remove_site_health_menu(){
remove_submenu_page( 'tools.php','site-health.php' ); 
}

//去除后台仪表盘菜单:活动、新闻

function bzg_remove_dashboard_widgets() {
global $wp_meta_boxes;

#去除 "活动" 

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);

#移除 "WordPress 新闻" 

unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
}
add_action('wp_dashboard_setup', 'bzg_remove_dashboard_widgets' );

//移除后台仪表盘菜单:帮助

function bzg_remove_help() {
get_current_screen()->remove_help_tabs();
}
add_action('admin_head', 'bzg_remove_help');

//移除后台页面title标题的wordpress后缀

add_filter('admin_title', 'delAdminTitle', 10, 2);
function delAdminTitle($admin_title, $title){
return $title.' ? '.get_bloginfo('name');
}

//去除进占页面title标题的wordpress后缀

add_filter('login_title', 'remove_login_title', 10, 2);
function remove_login_title($login_title, $title){
return $title.' ? '.get_bloginfo('name');
}

//转换经典文章编辑器(v5.x已经开始预设古腾堡编辑器)

add_filter('use_block_editor_for_post', '__return_false');

//严禁WordPress新版本文章编辑器前端读取样式文件

remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );

//替代评论用户头像链接为国内镜像快速出访

add_filter('get_avatar', function ($avatar) {
return str_replace([
'www.gravatar.com/avatar/',
'0.gravatar.com/avatar/',
'1.gravatar.com/avatar/',
'2.gravatar.com/avatar/',
'secure.gravatar.com/avatar/',
'cn.gravatar.com/avatar/'
], 'gravatar.wp-china-yes.net/', $avatar);
});
卓越飞翔博客
上一篇: wordpress和phpcms该怎么选择
下一篇: PHP过滤HTML标签代码方法
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏