I am adding an admin notice via the conventional admin_notice
hook in my plugin:
function my_admin_notice() { ?>
<div class="notice notice-info is-dismissible">
<p><?php _e( 'some message', 'my-text-domain' ); ?></p>
</div>
<?php
}
if ( my_plugin_show_admin_notice() )
add_action( 'admin_notices', 'my_admin_notice' );
How can I control where wordpress places the admin notice, in the html on the current screen, without using Javascript?
5 Answers
I found out by accident recently that all the notices will be moved to after the first <h2>
tag on the page inside a <div class="wrap">
. This gives you some slight control in that, for example, on a plugin settings page you can put an empty <h2></h2>
at the very top if you want to use <h2>Plugin Title</h2>
without it messing up the display formatting there.