Created
January 7, 2025 07:38
-
-
Save faisalahammad/43620bd616f729bed36a5865af8efc77 to your computer and use it in GitHub Desktop.
WordPress snippet to completely disable and remove all admin notices, dashboard notifications, update nags, and plugin notices. Works with all WordPress versions, prevents third-party plugins from showing notices, and follows WordPress coding standards. Can be used in themes, plugins, or with Code Snippets plugin.
This file contains 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
<?php | |
/** | |
* Disable Admin Notices WordPress | |
* Description: Completely removes all admin notices from the WordPress dashboard, | |
* including core WordPress notices and those added by plugins and themes. | |
* @author Faisal Ahammad <[email protected]> | |
*/ | |
// Exit if accessed directly | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* Main class to handle admin notice removal | |
*/ | |
class Admin_Notice_Remover { | |
/** | |
* Initialize the notice remover | |
* | |
* @return void | |
*/ | |
public function init() { | |
// Remove all admin notices | |
add_action('admin_init', [$this, 'remove_all_notices'], 1); | |
// Remove specific notice hooks | |
add_action('admin_head', [$this, 'remove_notice_output'], 1); | |
// Disable notice output | |
add_action('admin_notices', [$this, 'disable_notices'], 1); | |
add_action('all_admin_notices', [$this, 'disable_notices'], 1); | |
add_action('user_admin_notices', [$this, 'disable_notices'], 1); | |
add_action('network_admin_notices', [$this, 'disable_notices'], 1); | |
// Remove update nags | |
add_action('admin_init', [$this, 'remove_update_nags'], 1); | |
} | |
/** | |
* Remove all notices using remove_all_actions | |
* | |
* @return void | |
*/ | |
public function remove_all_notices() { | |
remove_all_actions('admin_notices'); | |
remove_all_actions('all_admin_notices'); | |
remove_all_actions('user_admin_notices'); | |
remove_all_actions('network_admin_notices'); | |
} | |
/** | |
* Remove notice output using CSS | |
* | |
* @return void | |
*/ | |
public function remove_notice_output() { | |
?> | |
<style> | |
.notice, | |
.notice-error, | |
.notice-warning, | |
.notice-success, | |
.notice-info, | |
.updated, | |
.error, | |
.update-nag { | |
display: none !important; | |
} | |
</style> | |
<?php | |
} | |
/** | |
* Disable notices by returning false | |
* | |
* @return bool | |
*/ | |
public function disable_notices() { | |
return false; | |
} | |
/** | |
* Remove update nags | |
* | |
* @return void | |
*/ | |
public function remove_update_nags() { | |
remove_action('admin_notices', 'update_nag', 3); | |
remove_action('admin_notices', 'maintenance_nag', 10); | |
} | |
} | |
// Initialize the notice remover | |
add_action('plugins_loaded', function() { | |
$notice_remover = new Admin_Notice_Remover(); | |
$notice_remover->init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment