Add Custom Error Messages to Admin Panel

Snippets by IsItWP

Do you want to display a custom error message within the theme admin page? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add custom error message to admin panel in WordPress.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

add_action( 'admin_notices', 'custom_error_notice' );
function custom_error_notice(){
     global $current_screen;
     if ( $current_screen->parent_base == 'themes' )
          echo '<div class="error"><p>Warning - If you modify template files this could cause problems with your website.</p></div>';

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 28 best WordPress resume themes to create best impression.

Comments   Leave a Reply

  1. Thanks. It really helps me…..

    1. Cool Arif glad I could help.

  2. How can you get this to display on the dashboard? I get get it to work on all the other menus such as tools, but not on the dashboard. Also, are there any other default WP classes I can use other than error? 

    1. You will notice on the line 04: $current_screen->parent_base == ‘themes’   you need to change the word themes to something else like “edit” etc. for development you can use this snippet to get the name of the current_screen.

      add_action( ‘admin_notices’, ‘current_screen’ );
      function current_screen() {
      if( !is_admin() ) return;
      global $current_screen;

      add this snippet to the functions.php of your wordpress theme and within the admin it will display the name you need to replace themes with. If you want the dashboard replace themes with index. Don’t forget to remove that snippet once done since you only need to it to get the parent_base. In regards to types of messages you can change class=”error” to updated.

  3. Elliott the web design guy June 2, 2011 at 10:32 pm

    That’s a great one, a lot of fun could be had with that 🙂

    1. @elliottrichmond:disqus  yes it is something you could use just as a message to display or tie it into a plugin etc. very useful.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!