移除 WordPress 后台中的“站点健康状态”

本文最后更新于 2024年5月9日,已超过 3 月没有更新,如果文章内容失效,请反馈给我们,谢谢!

wordpress5.0+的后台中多了一个“站点健康状态”模块,基本用不上,比较碍眼,可以使用以下方法把它去除。

先去除左侧“工具”-->“站点健康”这个菜单,在主题的function.php加入如下代码:

//移除侧边菜单中的站点健康
function remove_site_health_menu(){
  remove_submenu_page( 'tools.php','site-health.php' );
}
add_action( 'admin_menu', 'remove_site_health_menu' );

再移除仪表盘中的“站点健康状态”

//移除仪表盘中的站点健康模块,也是在主题的function.php加入如下代码:
function remove_dashboard_siteHealth() {
  remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' );
}
add_action('wp_dashboard_setup', 'remove_dashboard_siteHealth' );

仪表盘中的“站点健康状态”也可以使用如下代码一并与其它模块一并移除:

//移除仪表盘中的相关组件
function example_remove_dashboard_widgets() {
  // Globalize the metaboxes array, this holds all the widgets for wp-admin
  global $wp_meta_boxes;
  // 以下这一行代码将删除 "快速草稿" 模块
  unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
  // 以下这一行代码将删除 "WordPress活动及新闻" 模块
  unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  // 以下这一行代码将删除 "概况" 模块
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  // 以下这一行代码将删除 "动态" 模块
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
  // 以下这一行代码将删除 "站点健康状态" 模块
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_site_health']);
}
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );
© 版权声明
分享是一种美德,转载请保留原链接
THE END

文章不错?点个赞呗
点赞 0 分享

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部