Created
June 27, 2023 17:14
-
-
Save dartiss/81ae80888fd73708c73e3604948fc2e6 to your computer and use it in GitHub Desktop.
Remove WordPress admin notices for non-administrators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.