Skip to main content

Disable Site Health

PropertyValue
descriptionDisable WordPress Site Health admin UI access.
tagslib, php, wp, oop
rating

Overview

Disable WordPress Site Health UI access.

The snippet removes the Site Health submenu from single-site and network admin Tools menus, redirects direct access to site-health.php, catches Site Health screens through current_screen, and removes the Site Health dashboard widget.

Variants

<?php
/**
* Disable WordPress Site Health UI.
*/

/**
* Remove Site Health menu.
*/
if ( ! function_exists( 'mac_remove_site_health_menu' ) ) {

function mac_remove_site_health_menu(): void {
remove_submenu_page( 'tools.php', 'site-health.php' );
}
}

add_action( 'admin_menu', 'mac_remove_site_health_menu', 99 );
add_action( 'network_admin_menu', 'mac_remove_site_health_menu', 99 );

/**
* Redirect direct access.
*/
if ( ! function_exists( 'mac_redirect_site_health_access' ) ) {

function mac_redirect_site_health_access(): void {
wp_safe_redirect( admin_url( 'index.php' ) );
exit;
}
}

add_action( 'load-site-health.php', 'mac_redirect_site_health_access' );

/**
* Catch screen edge cases.
*/
if ( ! function_exists( 'mac_maybe_redirect_site_health_screen' ) ) {

function mac_maybe_redirect_site_health_screen( object $screen ): void {

$screen_id = (string) ( $screen->id ?? '' );

if (
$screen_id === 'site-health' ||
str_starts_with( $screen_id, 'tools_page_site-health' )
) {
wp_safe_redirect( admin_url( 'index.php' ) );
exit;
}
}
}

add_action( 'current_screen', 'mac_maybe_redirect_site_health_screen' );

/**
* Remove dashboard widget.
*/
if ( ! function_exists( 'mac_remove_site_health_dashboard_widget' ) ) {

function mac_remove_site_health_dashboard_widget(): void {
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' );
}
}

add_action( 'wp_dashboard_setup', 'mac_remove_site_health_dashboard_widget', 20 );