How to Add Custom Admin Notices in WordPress

Do you want to add admin notices in WordPress? Admin notices are used by WordPress core, themes, and plugins to display warnings, notices, and important on screen information to users. In this article, we will show you how you can add admin notices in WordPress.… Read More »

The post How to Add Custom Admin Notices in WordPress appeared first on WPBeginner.

Do you want to add admin notices in WordPress? Admin notices are used by WordPress core, themes, and plugins to display warnings, notices, and important on screen information to users. In this article, we will show you how you can add admin notices in WordPress.

How to Add Admin Notices in WordPress

Why and When to Use Admin Notices in WordPress?

WordPress uses admin notices to alert users about errors, warnings, and success messages.

Example of a default WordPress admin notice

Individual site owners, plugin authors, and theme developers can also use admin notices.

If you are working on a website for clients who are not familiar with WordPress, then you can add admin notices to display helpful information across their WordPress admin area.

Custom admin notices can also be helpful if you run a multi-author WordPress site. You can add notices to guide new authors and help them find their way around.

However, we recommend using admin notices carefully. They can be really annoying and may ruin the WordPress experience for your users.

Having said that, let’s take a look at how you can add your own custom admin notices in WordPress.

Method 1: Add Custom Notices in WordPress Manually

This method requires you to add code to your WordPress site. If you have never added code before, then take a look at our guide on pasting snippets from the web into WordPress.

Let’s get started.

First you need to add this code to your theme’s functions.php file or a site-specific plugin.

function general_admin_notice(){
    global $pagenow;
    if ( $pagenow == 'options-general.php' ) {
         echo '<div class="notice notice-warning is-dismissible">
             <p>This notice appears on the settings page.</p>
         </div>';
    }
}
add_action('admin_notices', 'general_admin_notice');

This code displays a notice on the settings page with a yellow border and a button to close the notice. This is how it will appear on your site:

Custom admin notice example

If you study the code, you will notice that we have used $pagenow variable to detect the current page.

After that we added the condition that checks if the current page meets the page where we want to display the notice.

If it does, then we show the notice wrapped in a <div> element. This div element uses CSS classes already defined in the WordPress admin stylesheet for different type of notices.

You need to use notice class and then you can add notice-error, notice-warning, notice-success, or notice-info.

Optionally, you can use is-dismissible class which adds a button to close the notice.

Apart from checking the current page, you can add all kind of conditions to show notices matching different scenarios.

For example, you want to display a notice only to users with the author user role.

Here is how you will do that:

function author_admin_notice(){
    global $pagenow;
    if ( $pagenow == 'index.php' ) {
    $user = wp_get_current_user();
    if ( in_array( 'author', (array) $user->roles ) ) {
    echo '<div class="notice notice-info is-dismissible">
          <p>Click on <a href="edit.php">Posts</a> to start writing.</p>
         </div>';
    }
}
}
add_action('admin_notices', 'author_admin_notice');

As you can see that we have added an extra check to detect the user role in our function.

This is how it will appear on your site.

Custom notice by user role

Feel free to practice with different conditions, filters, and hooks to play with admin notices.

Method 2: Add Admin Notices Using a WordPress Plugin

This method is simpler as it does not require you to add code. However, it is not as flexible as the custom code method.

First thing you need to do is install and activate the KJM Admin Notices plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings » KJM Admin Notices page to configure plugin settings.

KJM Admin Notices settings

First, you need to check the option to enable KJM Admin Notices. The second option adds a custom post type where you can add and edit your custom admin notices.

The plugin also allows you to send an email to registered users when you publish a new notice. You can check the box next to ‘Send Email’ option if you want to use this feature.

You can also enable comments for your notices which will allow users to respond to notices by adding comments. To enable this feature, check the box next to ‘Allow Comments’ option.

Don’t forget to click on the save changes button to store your settings.

You will now see a new menu item labeled notices in your WordPress admin bar. This is where you can add and edit your custom admin notices.

Let’s create your first admin notice.

Visit Notices » Add Notice page. You will see a screen much like the WordPress post edit screen.

Add new custom notice

Start by adding a title for your notice, then add the actual notice in the post editor. You can select the notice category from the box on your right hand.

Next you need to select the user roles which will see this notice.

Select user roles that will see the notice

You can optionally show or hide title, author and date, and the button to dismiss notice.

Once you are finished, click on the publish button and your custom admin notice will go live.

KJM admin notices

KJM Admin Notices allows you to manage your custom admin notices without writing any code. You can delete or unpublish notices that you don’t want to display any more.

Using the email feature, you can also use it to alert all your users even if they don’t log in to check notices.

Having problems sending emails? See our guide on how to fix WordPress not sending email issue.

You may also want to take a look at WP Notification Center plugin. It adds a Facebook-like notification center in WordPress. Users can click on the notification icon to see their notifications.

Notification center

That’s all. We hope this article helped you learn how to add custom admin notices in WordPress. You may also want to see our guide on how to create a custom user registration form in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Add Custom Admin Notices in WordPress appeared first on WPBeginner.

How to Add a Notification Center in WordPress

Are you tired of the annoying WordPress notifications that are added by various different plugins and themes? Want to control these notifications? In this article, we will show you how to add a notification center in WordPress that takes these notices out of your way… Read More »

To leave a comment please visit How to Add a Notification Center in WordPress on WPBeginner.

Are you tired of the annoying WordPress notifications that are added by various different plugins and themes? Want to control these notifications? In this article, we will show you how to add a notification center in WordPress that takes these notices out of your way and places them under a convenient menu.

Yep, you can make it just like the Facebook notifications area.

When and Why You Should Add a Notification Center in WordPress?

WordPress allows plugins and themes to display notices in the admin area. Sometimes these notifications can become annoying and get in your way of doing other things.

Does this look familiar?

Notifications in the admin area of a WordPress site

If you are developing a site for a client, then the notifications issued by the plugins may ruin user experience in the admin area. Your work would look unfinished and unpolished.

When running a multi-author WordPress site, some of these notifications may be visible to other authors as well. These authors can’t take the actions suggested by the notices, and it becomes a bit annoying for them because they can’t even dismiss them.

Thankfully you can fix this by adding a notification center.

Setting up WP Notification Center

First thing you need to do is install and activate the WP Notification Center plugin. It works out of the box, and there are no settings for you to configure.

Upon activation, the plugin will simply add a new Notifications menu in your WordPress toolbar. This notification center will capture notices displayed by WordPress plugins.

New notifications indicated by a number in the notifications menu

New notifications are indicated by a number, and you can review these notifications by taking the mouse over to the notification menu.

Currently there is no way to dismiss a notification from the notification center. These notifications will ONLY disappear when you take the required action recommended in the actual notice.

WordPress Notification Center

You may also notice that the number of notifications will change from one page in the admin area to another. This is because the original plugins or themes showing these notifications may have them configured to be displayed on certain pages only.

WP Notifications Center provides a friendly experience for clients and authors on your website. It reduces the clutter while making sure that you don’t miss anything important.

We hope this article helped you add a notification center to your WordPress site. You may also want to see our list of 13 plugins and tips to improve WordPress admin area.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

To leave a comment please visit How to Add a Notification Center in WordPress on WPBeginner.