How to show a notification in WP admin pages

Sometimes you need to inform your users about that specific thing that’s happening on the site. If you have a lot of authors, contributors and registered users who are used to logging into your site, leaving a notification in the admin area might be a nifty idea when you are about to change something.

For example, you might want to put a site under maintenance so it would be polite to notify your registered users about what you’re about to do in advance. They will definitely like your awareness.

In the following lines, we’re about to show you a code which will create a dashboard notification message for all of your users.

Show a notification in the admin area:

  1. Locate functions.php file in your theme and open it
  2. Copy and paste this code:
  3. function wp_admin_notification () {
    echo ' <div class="error">
    <p>We are about to put our site under maintenance mode. Please don’t do any modifications until 6:00 PM.</p>
    </div>';
    }
    add_action( 'admin_notices', ' wp_admin_notification ' );
    
  4. Save changes

Of course, don’t forget to change the little text we have put in the paragraph and write anything you want. Nice, isnt’ it?

While this little function will show dashboard notification to all of your registered users, sometimes you will want to display a message only for your other admins. Whether you want to try out the code and say hello to your fellow colleagues or you really need to notify them about something important such as theme and plugin updates or ongoing changes, you will need to slightly modify the code:

  1. Open the same functions.php file
  2. Copy and paste the following code:
  3. function wp_admin_notification () {
    if ( current_user_can('manage_options') ) {
    echo ' <div class="error">
    <p>Hey fellow admins. Please don’t update plugins until further notice.</p>
    </div>';
    }
    }
    add_action( 'admin_notices', ' wp_admin_notification ' );
    
  4. Save changes.

That’s it. Now you have a simple yet powerful tool for displaying short messages to your admins, other colleagues or to all your registered users – we hope there are thousands of them already.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

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