Display an admin notice that can be dismissed

 In Admin, All

How to display an admin notice that can be dismissed action.

/* Display an admin notice that can be dismissed */

add_action('admin_notices', 'ns_example_admin_notice');
function ns_example_admin_notice() {

 global $current_user ;
 $user_id = $current_user -> ID;

 /* Check that the user hasn't already clicked to ignore the message */
 if ( ! get_user_meta($user_id, 'example_ignore_notice') ) {

  echo '<div class="updated"><p>';
  printf(__('This is an annoying nag message. Why do people make these? | <a href="">Hide Notice</a>'), '?example_nag_ignore=0');
  echo "</p></div>";



add_action('admin_init', 'ns_example_nag_ignore');
function ns_example_nag_ignore() {

 global $current_user;
 $user_id = $current_user->ID;

 /* If user clicks to ignore the notice, add that to their user meta */
 if ( isset($_GET['ns_example_nag_ignore']) && '0' == $_GET['ns_example_nag_ignore'] ) {
   add_user_meta($user_id, 'ns_example_ignore_notice', 'true', true);


Probally you may be also interested in display custom messages to returning visitors @ https://www.wp-code.uk – Nuno Sarmento

Recommended Posts

Start typing and press Enter to search

Let's work together

I'd love to work with you! Please fill out my project form to tell me more about your project/work. I reply to all enquiries within 48 hours.


  • January - Available
  • February - Available
  • March - Available


  • My day rate is £300.
  • I can provide a fixed price for your work.

EN - Header Enquiry Form

  • This form collects your name, email address and telephone number so that I can respond to the enquiry(ies) that you submit via this website. Please check my privacy policy for the full story on how I use, protect and manage your submitted data.