Skip to content

Instantly share code, notes, and snippets.

@dartiss
Created June 27, 2023 17:14
Show Gist options
  • Save dartiss/81ae80888fd73708c73e3604948fc2e6 to your computer and use it in GitHub Desktop.
Save dartiss/81ae80888fd73708c73e3604948fc2e6 to your computer and use it in GitHub Desktop.
Remove WordPress admin notices for non-administrators
function dismiss_admin_notices() {
// Check if the current user is not an administrator.
if ( ! current_user_can( 'administrator' ) ) {
// Dismiss all admin notices.
remove_all_actions( 'admin_notices' );
}
}
add_action( 'admin_init', 'dismiss_admin_notices' );
@dartiss
Copy link
Author

dartiss commented Jun 27, 2023

For some odd reason WordPress shows admin notices (note the use of the word "admin") to everyone, not just admins. This script, when added to functions.php will remove all the messages for non-admins.

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