Complete Guide to WordPress Admin Notices


Dig WP has just published a post “Complete Guide to WordPress Admin Notices” and I am sure it’s helpful for you guys.

There are 4 types of admin notices in WordPress:

  1. Success – displayed when something good happens, like settings updated successfully
  2. Error – displayed when an error or something bad happens
  3. Warning – displayed when the user should be warned of something
  4. Information – displayed to communicate information to the user

The source code of these different types of admin notices basically is the same. The only difference are the class names and the message. The classes of above 4 types of notices are:

  1. notice-success – success message displayed with a green border
  2. notice-error – error message displayed with a red border
  3. notice-warning – warning message displayed with a yellow border
  4. notice-info – info message displayed with a blue border

If you want to add default admin notices, you can use following 2 methods:

  1. Add settings_errors() explicitly to your displayed settings
  2. Add settings_errors() via admin_notices hook

Or you want to add custom admin notices by:

  1. Hook it into admin_notices
  2. Use add_settings_error() directly in your settings validation function
  3. ( Quick Fix only!!! ) Add custom admin notices just about anywhere
    <?php if (isset($_GET['settings-updated'])) : ?>
    	<div class="notice notice-success is-dismissible"><p><?php _e('Something happened!'); ?>.</p></div>
    <?php endif; ?>

Author: Leo

My name is Leo who's behind this blog. I've been working with wordpress since 2010. I'll write about themes, plugins, tutorials and all about wordpress here. Hope you find it useful!

Leave a Reply

Your email address will not be published. Required fields are marked *