Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Display Messages in the Dashboard with Admin Notices

Posted on October 27, 2011 by Pippin in Free Members, Intermediate, Member Restricted, Tutorials, Video Tutorials, WordPress Admin / Dashboard 13 Comments
Home» Member Restricted » Free Members » Display Messages in the Dashboard with Admin Notices
Tweet
Love It - 1

Ever noticed the messages WordPress displays when you activate a plugin, or save settings? Or the messages that some plugins show in the dashboard, perhaps notifying you of a missing requirement? These are called Admin Notices and I’m going to show you how to add your own in your plugin or theme. They’re really quite easy to add.

To display an admin notice, we’re going to write one function, and it can be placed just about anywhere. If you’re trying this with a theme, then I recommend you place this in your functions.php. If you’re trying this with a plugin you’ve just started, then I’d recommend placing this in your main plugin file. The function does nothing more than echo out the message we’d like displayed. The message is wrapped in a little bit of HTML that will style it the same as the built-in admin notices.

You must be logged in to view the rest of this content. Register or login from the sidebar.

Tweet Follow @pippinsplugins
admin_notices

13 comments on “Display Messages in the Dashboard with Admin Notices”

  1. GreggFranklin says:
    December 18, 2011 at 11:39 am

    Thanks for the tutorial! I am not sure how to conditionally pick a specific page to add this to. For example I have a page that is using a custom template (Testimonials) and I want to let the user know. In the video you mentioned you looked at the url for the slug, I don’t see that.

    Reply
    • Pippin says:
      December 19, 2011 at 9:22 am

      @Gregg – It sounds like you’re trying to display notices on the front end of the site, is that correct? If so, then this will not do that. This code is just for displaying notices in the admin section.

  2. manifestphil says:
    February 28, 2012 at 12:11 pm

    Hi Pippin,

    I’m having some trouble logging in to view this article. Entering my username and password on the sidebar returns me to this article, but the “Members Only” content is not displayed. I reset my password, and am able to login via the wp-login.php file to my profile.

    Using Safari 5.0.6, Mac OSX 10.5

    Reply
    • manifestphil says:
      February 28, 2012 at 12:12 pm

      Odd. After submitting my comment, I’m now logged in. Refreshing the page didn’t help, but perhaps this loaded the appropriate cookie.

    • Pippin says:
      February 28, 2012 at 12:40 pm

      Interesting. Let me know if it happens again.

  3. Bryce says:
    August 4, 2012 at 8:37 am

    Hey Pippin. How would you set it to only display once after a theme’s activation? Is there a better way than:

    // show admin notice after theme activation
    function spiritualized_admin_notices() {
    if(isset( $_GET['activated'] )) {
    ob_start(); ?>

    Thank you for using Spiritualized! First thing you should do is <a href="/wp-admin/nav-menus.php">add your custom header and footer menus. You should then check out the Theme Options.

    <?php
    echo ob_get_clean();
    }
    else {
    }
    }
    add_action('admin_notices', 'spiritualized_admin_notices');

    Reply
    • Pippin says:
      August 5, 2012 at 10:47 pm

      That method should work fine, except that it will show any time a plugin or theme is activated. You need to add in another check to make sure it’s only your theme.

    • Bryce says:
      August 5, 2012 at 11:02 pm

      I’m assuming it won’t show when another theme (not mine) is activated as the code shouldn’t run without the theme active, so what would be the easiest way to limit it to JUST theme activations? :)

    • Pippin says:
      August 6, 2012 at 4:43 pm

      It should work to just add this:

      1
      2
      3
      4
      
      global $pagenow;
      if( isset( $_GET['activated'] ) && 'themes.php' == $pagenow ) {
          // show notice
      }
  4. bryceadams says:
    August 17, 2012 at 9:30 am

    Perfect, thank you Pippin

    Reply
  5. Marko says:
    February 27, 2013 at 6:37 am

    Hi Pippin. I am doing messages, not a strange stuff for me, but I noticed interesting behavior lately which can’t resolve myself still!

    The thing is that ONLY on Permalink Settings page (you know the wp-admin/options-permalink.php page) notices show twice! Could you check that out please, and let us know if you found a fix?

    FYI, I have WordPress multi-site installed, didn’t try on single installation. On any other page notice is shown only once (of course). I’m doing it from plugin, not from functions.php for example.

    Reply
    • Pippin says:
      March 4, 2013 at 8:13 pm

      Can you please show me the code you’re using?

    • Marko says:
      March 7, 2013 at 4:42 am

      I noticed that this is behavior on WordPress running on Nginx server. I was only checking current screen and is POST set inside admin_notices action, like:

      add_action(‘admin_notices’, ‘cool_function’);
      function cool_function() {
      …
      if (‘options-permalink’ == $current_screen->base) {
      if (isset($_POST['submit'])) {
      … some logic and echo here …
      }
      }

      As I mentioned it’s running on Nginx, so found this page:
      http://codex.wordpress.org/Nginx

      And added this:
      add_filter( ‘got_rewrite’, ‘__return_true’ );
      before actions. Now works :) if you have any thoughts about this let me(us) know.. anyway it’s one more information about this.

Leave a Reply Cancel reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

  • Review: Easy Admin Notification
  • Admin Notices in the Network Admin

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes
  • Plugin Development 101 – Registering a Custom Post Type
  • Plugin Development 101 – Intro to Actions

Latest Tutorials

  • Test Your Plugins with RTL (0)

    Right-To-Left languages are those that...

  • Submitting Your First Pull Request to a WordPress Plugin on Github (5)

    Github is an extremely popular tool for managing WordPress plugins, and one...

  • Plugin Development 101 – Introduction to Adding Dashboard Menus (1)

    Adding new menus, both top level and sub level, to the WordPress Dashboard is a really common task for plugins...

Enter your email to receive automated updates when new posts are published

Latest Tweets

  • RT @strickland: Afternoon crowd: To celebrate Memorial Day weekend @gittyapp is on sale through Monday. Now is the time to join in! http:/…
    May 25, 2013
  • .@itsananderson wins!
    May 25, 2013
  • @nhangen It is correct for some products, wrong for others
    May 25, 2013

Topics

register_setting contextual help attachments add_shortcode hook featured campaign monitor wp_enqueue_script Rémi Corson shortcodes the_content get_user_meta Sugar Event Calendar plugin authors attachment image forms login short codes do_action Related posts mail chimp comments recent posts post types apply_filters bbpress short code taxonomies custom post type gallery Ajax images Stripe taxonomy jquery users widgets add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2013 Pippin's Plugins