Skip links

WordPress Admin Experience: How to Hide Admin Notices Efficiently

Are you tired of cluttered WordPress admin panels filled with distracting notices? Do you wish to streamline your workflow by removing unnecessary notifications? Look no further! In this article, we’ll explore a simple yet effective solution to declutter your WordPress admin interface and enhance your productivity.

				
					
/**
 * Hide all admin notices in WordPress admin panel.
 *
 * This function hooks into the 'admin_enqueue_scripts' action and removes
 * all admin notices by unsetting them from the global $wp_filter.
 * This includes notices set on the user admin, regular admin, and any
 * other admin notices collected in 'all_admin_notices'.
 */
add_action('admin_enqueue_scripts', function() {
    global $wp_filter; // Access the global variable that stores all WordPress filters.

    // Check if current screen is user admin screen.
    if (is_user_admin()) {
        // Remove user admin notices if they exist.
        if (isset($wp_filter['user_admin_notices'])) {
            unset($wp_filter['user_admin_notices']);
        }
    } elseif (isset($wp_filter['admin_notices'])) {
        // Remove regular admin notices if they exist.
        unset($wp_filter['admin_notices']);
    }

    // Remove any other admin notices.
    if (isset($wp_filter['all_admin_notices'])) {
        unset($wp_filter['all_admin_notices']);
    }
});

				
			

Understanding the Code

This snippet of PHP code provides a straightforward solution to hide all admin notices within the WordPress admin panel. Let’s break it down step by step:

  1. Hooking into ‘admin_enqueue_scripts’ Action: The add_action function is used to hook into the ‘admin_enqueue_scripts’ action, which is fired when scripts and styles are enqueued for the admin panel.
  2. Accessing Global Variable: We access the global variable $wp_filter, which stores all WordPress filters.
  3. Removing Admin Notices:
    • If the current screen is the user admin screen (is_user_admin()), we unset the ‘user_admin_notices’ filter to remove user-specific admin notices.
    • If not, we unset the ‘admin_notices’ filter to remove regular admin notices.
    • Additionally, we remove any other admin notices collected in the ‘all_admin_notices’ filter.

Benefits of Hiding Admin Notices

By implementing this code snippet, you can enjoy several benefits:

  • Enhanced Focus: Eliminate distractions caused by unnecessary admin notices, allowing you to focus on essential tasks without interruptions.
  • Improved User Experience: Create a cleaner and more organized admin interface for yourself and other users, enhancing overall user experience.
  • Increased Productivity: Save time and boost productivity by reducing visual clutter and streamlining your workflow within the WordPress admin panel.

Implementation

To implement this solution on your WordPress site, follow these simple steps:

  1. Access Theme Functions: Open your theme’s functions.php file or create a custom plugin for adding custom code snippets.

  2. Insert Code Snippet: Paste the provided PHP code snippet into the appropriate file.

  3. Save Changes: Save the file and refresh your WordPress admin panel to see the changes take effect immediately.

Conclusion

With this efficient code snippet, you can effectively hide admin notices in the WordPress admin panel, creating a cleaner and more focused environment for managing your website. Say goodbye to distractions and hello to enhanced productivity as you streamline your WordPress admin experience!


Leave a comment