Blog

WordPress Admin Notices Explained – Here’s How They Work

Posted on October 31st, 2020

Looking to provide guidance, feedback, warnings, error messages, or any other useful information in your WordPress? One simple and effective way to go about this is with the help of Admin notices. It’s an easy way to communicate with users—facilitating timely action.

But how do WordPress Admin notices work? And when should you use them? Below are answers to these questions and more.

First Things First; Admin notices in a Nutshell – Types and Reasons to Add Them

If you’re familiar with anything WordPress, then you might have noticed that there are visual differences when it comes to Admin Notices. This is because WordPress offers 4 classifications depending on your needs. They include:

1. Informational Notices: You can use this option to send out small bits of information that you believe users should know.

2. Error Notices: Is something off? Malfunctioning? The error Admin Notices are the way to go.

3. Success Notices: Let’s assume you’ve updated some plugins or installed a new theme; such information is displayed via Success Notices.

4. Warning Notices: If there are any security or critical issues, warning Admin Notices allow you send out the message for timely action.

PS: You can create custom WordPress Admin Notices, but it’s advisable to maintain the same color scheme and other relevant aspects to help users differentiate the meaning of the notices.

As highlighted earlier, Admin Notices typically enhance usability by offering important data and suggestions. For developers, Admin notices offer an ideal way to promote a feature or premium functionality—as long they’re used in a manner that’s reasonable and not annoying for the user.

Steps to Add Admin Notices in WordPress Manually

Relax; just because it’s a manual process doesn’t mean it’s complicated. WordPress does much of the heavy lifting for you in the form of pre-existing ‘hooks’ and default alert styles.

All you have to do is add (*more of copy-paste) some lines of code into your active theme’s functions.php file or create a custom code plugin containing the code to the notice. Below is an example of how you can add admin notices manually.

function notice_example(){    global $pagenow;    if ( $pagenow == ‘options-general.php’ ) {         echo ‘<div class=”notice notice-warning is-dismissible”>             <p>You are on the settings page!</p>         </div>’;    }}add_action(‘admin_notices’, ‘notice_example’);

The parameter notice_example is a new function—and it basically checks if you are in the ‘settings’ page of your WordPress. If you are, you’ll see the “You’re on the settings page!” Warning Admin Notice. But ensure the admin notice is dismissible by the user.

Steps to Add Custom Admin Notices in WordPress Using a Plugin

While hard-coding Admin Notices into your project’s core is the best forward, there are a few plugins that serve the purpose. On such plugin is KJM Admin Notices—and here’s how it works:

  • Install the plugin and navigate to the New Notices
  • Select Add Notice to use your WordPress editor to craft a message (title and body text).
  • Publish your Admin Notice for it to appear automatically on a page.
  • Customize the Admin notices—including changing the colors, hiding some parameters, and deciding who can view it.
  • You can easily change the default style (Error Notice, Warning Notice, Success Notice, etc.) later from the Notice Cats

If you’re overwhelmed by the number of Admin Notices and you want to bring some order to the chaos, there’s a tool for that. Admin Notices Manager is an intuitive plugin that gets important to end-users—but in a clean orderly manner.