Are you able to share a screenshot to show what you mean?
Or a gif, or movie clip?
Jose here are two screenshots.
Notices 1
Notice 2
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.
No! I am using this code to debug the admin_notices hook.
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.ww.wp.xz.cn/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.ww.wp.xz.cn/browser/tags/4.9.7/src/wp-admin/js/common.js#L514
Hope this helps shed some light. I know it did for me. 🙂
Is there a way to fix this without writing a lot of code?
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/
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');