Title: admin_notices hook doesn&#8217;t work correctly.
Last modified: July 19, 2018

---

# admin_notices hook doesn’t work correctly.

 *  [mlc1959](https://wordpress.org/support/users/mlc1959/)
 * (@mlc1959)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/)
 * I am testing the admin_notices hook in a plugin with the following code.
 *     ```
       function sample_admin_notice__success() {
           ?>
           <div class="notice notice-success is-dismissible">
               <p><?php _e( 'Done!', 'textdomain' ); ?></p>
           </div>
           <?php
       }
       add_action( 'admin_notices', 'sample_admin_notice__success' );
       ```
   
 * For some reason the notices are displayed above the title and then move below
   it. I tried searching Google and the WordPress forums for a solution but didn’t
   find any. Is there a way to fix this problem? I am testing WordPress on my localhost
   and this is the only plugin activated.
 * Thank
 * Marcus
    -  This topic was modified 7 years, 10 months ago by [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/).
    -  This topic was modified 7 years, 10 months ago by [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/).
      Reason: added backticks to code

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [7 years, 10 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10510455)
 * Are you able to share a screenshot to show what you mean?
 * Or a gif, or movie clip?
 *  Thread Starter [mlc1959](https://wordpress.org/support/users/mlc1959/)
 * (@mlc1959)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10510537)
 * Jose here are two screenshots.
 * [Notices 1](http://www.mlcarey.com/admin_notices.png)
 * [Notice 2](http://www.mlcarey.com/admin_notices2.png)
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [7 years, 10 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10515274)
 * Is that really the only thing that you are doing?
 * If so, I’ll test on my local install to see if I get the same result.
 *  Thread Starter [mlc1959](https://wordpress.org/support/users/mlc1959/)
 * (@mlc1959)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10515531)
 * No! I am using this code to debug the admin_notices hook.
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [7 years, 10 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10515652)
 * Gotcha.
 * Had to take a look at the code and part of that is because of the way the DOM
   is loaded. The hook is fired here: [https://core.trac.wordpress.org/browser/tags/4.9.7/src/wp-admin/admin-header.php#L255](https://core.trac.wordpress.org/browser/tags/4.9.7/src/wp-admin/admin-header.php#L255)
 * Which if you take a close look at the markup happens just before the most of 
   the `<h1>Heading Title for the page</h1>`
 * It is then moved via JavaScript here: [https://core.trac.wordpress.org/browser/tags/4.9.7/src/wp-admin/js/common.js#L514](https://core.trac.wordpress.org/browser/tags/4.9.7/src/wp-admin/js/common.js#L514)
 * Hope this helps shed some light. I know it did for me. 🙂
 *  Thread Starter [mlc1959](https://wordpress.org/support/users/mlc1959/)
 * (@mlc1959)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10515902)
 * Is there a way to fix this without writing a lot of code?
 *  [vemman](https://wordpress.org/support/users/vemman/)
 * (@vemman)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10810765)
 * Just adding my two bits on this. Been trying to get to display some info messages
   for during save_post (after validating some custom meta fields) for a woocommerce
   admin side order.
 * After searching through length and breadth of various sites & forums, I could
   only get a custom message displayed with this
 * [https://onextrapixel.com/10-tips-for-a-deeply-customised-wordpress-admin-area/](https://onextrapixel.com/10-tips-for-a-deeply-customised-wordpress-admin-area/)
 *     ```
       function frl_on_save_post($post_id, $post) {/* add warning filter when saving post */
   
           if($post->post_type == 'post') //test for something real here       
               add_filter('redirect_post_location', 'frl_custom_warning_filter');
   
       }
       add_action('save_post', 'frl_on_save_post', 2, 2);
   
       function frl_custom_warning_filter($location) { /* filter redirect location to add warning parameter*/
   
           $location = add_query_arg(array('warning'=>'my_warning'), $location);
           return $location;
       }
   
       function frl_warning_in_notice() { /* print warning message */
   
           if(!isset($_REQUEST['warning']) || empty($_REQUEST['warning']))
               return;
   
           $warnum = trim($_REQUEST['warning']);
   
           /* possible warnings codes and messages */                 
           $warnings = array(
               'my_warning' => __('This is my truly custom warning!', 'frl')
           );
   
           if(!isset($warnings[$warnum]))
               return; 
   
           echo '<div class="error message"><p><strong>';
           echo $warnings[$warnum];
           echo '</strong></p></div>';
       }       
       add_action('admin_notices', 'frl_warning_in_notice');
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘admin_notices hook doesn’t work correctly.’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [vemman](https://wordpress.org/support/users/vemman/)
 * Last activity: [7 years, 7 months ago](https://wordpress.org/support/topic/admin_notices-hook-doesnt-work-correctly/#post-10810765)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
