Wordpress - Create an Info/Help message at top of a custom post type
The hook you are after is admin_notices
. This is fired at the top of every admin page.
If you wish to restrict the notice to certain pages you can use: get_current_screen() to get the current screen.
$screen = get_current_screen();
You can wrap the notices in div
elements with class 'error' or 'updated' to get the red, or yellow styled notices.
For instance:
function wpse51463_admin_notice(){
$screen = get_current_screen();
//If not on the screen with ID 'edit-post' abort.
if( $screen->id !='edit-post' )
return;
?>
<div class="updated">
<p>
A notice on the post list screen
</p>
</div>
<div class="error">
<p>
An error message
</p>
</div>
<?php
}
add_action('admin_notices','wpse51463_admin_notice');
For a plug-ins settings page (nested under the Settings tab) the screen id should be settings_page_{page-name}
. You can of course determine the id of a page by using the above to print the current screen id of every page.
If you want something like this:
Then here's something that does the job:
add_action('admin_footer','print_mynote');
function print_mynote(){
global $typenow,$pagenow;
if (in_array( $pagenow, array( 'post.php', 'post-new.php' )) && "Post_Type_Name" == $typenow ) {
?>
<SCRIPT TYPE="text/javascript">
jQuery(document).ready(function(){
var myDiv = jQuery('<div>');
myDiv.css("border","1px dashed #000000");
myDiv.css("padding","5px");
myDiv.css("background","lightyellow");
myDiv.css("width","70%");
myDiv.html("PUT your info help message here....");
jQuery(".wrap").find("h2").after(myDiv);
});
</SCRIPT>
<?php
}
}
Just make sure you change Post_Type_Name
to the name of your post type, and change PUT your info help message here....
to your actual message.