Home Blog WordPress Management What are WordPress admin notices (and how do they work)?

What are WordPress admin notices (and how do they work)?

Even if you’re new to WordPress, you’ll be familiar with admin notices. They’re the messages that show up on your dashboard to let you know about updates, errors, changes and more.

Admin notices give you critical information about your site, which enables you to take timely action. Moreover, if you’re a theme or plugin developer, knowing how to add admin notices to WordPress is important since they allow you to easily communicate messages to your users.

In this article, we’ll go over the different types of admin notices you can use. We’ll talk about situations where it makes sense to use admin notices and then teach you how to add them to WordPress. Let’s get to work!

What Are the different types of admin notices in WordPress?

You may have noticed that not all WordPress admin notices look the same. By default, WordPress uses four different styles depending on the purpose of the notices it shows:

  1. Success. This is the type of notice you’ll see when making changes to your website (such as a plugin install or activation) and it goes off without a hitch.
  2. Error. As its name implies, you’ll see this type of message if there’s something wrong with your website. Typically this is used when a plugin or theme generates an error.
  3. Warning. You’ll see this type of notice pop up when a plugin or website component is working, but not working as expected.
  4. Information. This type of admin notice is perfect to communicate simple bits of information.

As we mentioned before, those four classifications are styles you can use for admin notices. Each individual notice works the same under the hood, so you only see a visual difference. Here are some examples:

Example of admin notices.
WP 2FA admin notice
Activity Log & Yoast SEO admin notice

If you’re planning on adding custom admin notices to your website (or to a plugin or theme you’re working on) it’s important you follow the same classification. The simple color scheme can help users identify which notices to prioritize at a glance. For example, if we see a red (an error) or a yellow (a warning) notice, we know something is wrong.

With this in mind, let’s talk about when it makes sense to use WordPress admin notices.

Why should you add custom WordPress admin notices?

Admin notices in WordPress are all about usability, and can provide users with feedback and critical information. For example, success notices. If you update one of your plugin’s settings and save the changes, the success notice provides visual confirmation of the process:

Visual confirmation of the success process

For your own website, adding custom notices might not be necessary unless multiple users have access to the dashboard. In this case, you can use informational notices to provide members of your team with quick updates.

WordPress admin notices for plugins & themes developers

Many plugin developers also use admin notices to communicate important information to their users. They are also typically used to promote the premium functionality of the plugin or theme.

Keep in mind that not all users enjoy getting bombarded with admin notices, though. For years, there’s been a healthy debate in the WordPress community about the way that developers use notices.

Improper use of admin notices can (and has) resulted in a significant backlash in some cases. In a nutshell, you need to be careful about what situations you decide to implement admin notices in. In the next section, we’ll discuss how to add admin notices, and provide some tips for standardizing them.

TIP: Managing admin notices in WordPress

If you have too many admin notices on your WordPress but you do not want to dismiss them before you read them (when you have time), but they are distracting you, use the Admin Notices Manager plugin to move all the admin notices in one central place and read them at your own convenience.

How to add admin notices in WordPress (2 ways)

Let’s now teach you how to add admin notices in WordPress in two ways. First, we’ll go over the manual approach and then we’ll show you how to add admin notices using a plugin.

1. Add admin notices manually

Since WordPress already provides default styles for admin notices, adding new notifications to your website isn’t as complicated as you might think. That is because you can use existing ‘hooks’ to call up different alert styles.

In any case, you’ll need to add a few code snippets to your website. There are two approaches you can take when it comes to implementing admin notices manually:

  1. Add the code to your active theme’s functions.php file.
  2. Create a custom code plugin for WordPress that includes the notice’s code.

Which approach you use will depend on what you plan to use admin notices for. Here’s a quick example of a custom admin notice that displays the message “You’re on the settings page!”:

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');

Here, we’re registering a new function called notice_example. This function checks if you’re currently in the WordPress Settings page. If you are, it displays the “You’re on the settings page!” message using the warning admin notice style.

You’ll also notice the is-dismissible parameter. This enables the end-user to dismiss or close the notice, which is always recommended. This is how it looks:

Example of an admin notice

If you want to create custom admin notices for specific actions, you’ll want to take a look at the WordPress developer handbook, which includes all the information you need. What’s more, theme authors should take a look at the WPTRT GitHub page. This provides a custom class to help you create standardized admin notices that are dismissible for the end user by default.

Next, let’s look at using a plugin to create WordPress admin notices.

2. Use a plugin to add custom admin notices

There aren’t all that many plugins that enable you to set up custom admin notices in WordPress. This is because the functionality is usually beyond the needs for most plugin users, and admin notices are better off hard coded into your project’s core.

Even so, our recommended option here is KJM Admin Notices:

KJM Admin Notices

Once you install the plugin, you can set up new admin notices by going into the new Notices tab on your dashboard:

Notices Tab

Click on Add Notice and you’ll be able to use the WordPress editor to put together the message you want. With this plugin, you can divide notices into two parts. The title will appear more prominently and its body includes text that shows up right below:

Adding custom messages

Once you publish a notice, you’ll see it appear automatically at the top of whichever page you’re on:

Published notices

After you customize your notice’s message, you can decide which user roles will be able to see it:

Assigning user roles

This feature makes the plugin a fantastic option if you’re working with a big team, since you get full control over who sees each message. Moreover, the plugin also enables you to change some aspects of how your notices look. For example, you can choose to hide its title, who published it, and even change its colors:

Notice display options

As with any other piece of content you create using the WordPress editor, you can save your admin notices as drafts or schedule them instead of publishing them right away. Finally, you can change the default style that your notices use through the Notice Cats menu to the right:

Notice Cat menu

For our example, we used the SUCCESS style. However, remember that you should change the style you use depending on what type of admin notice you want to send.

Add Custom Admin Notices in WordPress

Paying attention to admin notices can help you ensure that your site is always in the best shape possible. Beyond maintaining your site, knowing how to add admin notices in WordPress is critical if you plan to create custom themes or plugins.

There are two ways you can add admin notices in WordPress, which are:

  1. Add admin notices manually using code.
  2. Use a plugin to add custom admin notices.

User tip: If you just want more control over existing admin notices or ensure that you don’t miss any key notices, don’t forget to use the Admin Notices Manager to manage all admin notices on WordPress. With this plugin, you’ll be able to quickly access an admin notice ‘inbox’ that includes all notices. The result is a cleaner experience for the end user, while still getting vital information to them.


One thought on “What are WordPress admin notices (and how do they work)?

  1. I’m a newbie in WordPress, this article was so much helpful for me to get to know about Admin Notices in WordPress properly. Thanks for this awesome and informative article. please keep it up.


Leave a Reply

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

Stay in the loop

Subscribe to the Melapress newsletter and receive curated WordPress management and security tips and content.

Newsletter icon

It’s free and you can unsubscribe whenever you want. Check our blog for a taste.

Envelope icon
newsletter-pop-up