Skip to content

Instantly share code, notes, and snippets.

@digisavvy
Last active June 27, 2023 03:23
Show Gist options
  • Save digisavvy/174a8a65accce24d9bc8c8f2441e9bdb to your computer and use it in GitHub Desktop.
Save digisavvy/174a8a65accce24d9bc8c8f2441e9bdb to your computer and use it in GitHub Desktop.
hide admin notices in WordPress.
add_action('admin_enqueue_scripts', 'ds_admin_theme_style');
add_action('login_enqueue_scripts', 'ds_admin_theme_style');
function ds_admin_theme_style() {
if (!current_user_can( 'manage_options' )) {
echo '<style>.update-nag, .updated, .error, .is-dismissible { display: none; }</style>';
}
}
@Kyzoe
Copy link

Kyzoe commented Feb 2, 2020

hey Alex,

Thanks for the snippet, but it doesn't seem to work anymore, just letting you know.

@norval101
Copy link

Hello Kyzoe,
You could just block it overall in notice by adding the below to the funtion.php file:

{
echo '<style>.wp-core-ui .notice.is-dismissible { display: none; }</style>' ;
}

@devuri
Copy link

devuri commented Feb 21, 2021

Works as expected thanks, here is my version. just use in functions file or small plugin.

small plugin: https://github.com/devuri/hide-wp-admin-notices

add_action('admin_enqueue_scripts', function () {
	if ( ! current_user_can( 'manage_options' ) ) {
		echo '<style>.update-nag, .updated, .error, .is-dismissible { display: none; }</style>';
	}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment