How to place HTML below the title of the (custom) post overview

Edit: Yes, I know, I provided an answer to this question myself. However, I’m still interested in other solutions and/or comments on the one I found. Is this how you would do this? Are there any other ways?


I would like to provide some additional description and on-page help (i.e., no contextual help or help tabs) on the overview page (i.e., edit.php) for a custom post type.

According to edit.php (as well as class-wp-list-table.php and class-wp-posts-list-table.php) there is no appropriate hook.

So, how can I do this?

A few notes:

  • I came up with a solution, which I would describe a bit hackish, so I’m open for a clean solution (if there is one);
  • I will post my solution as an answer so you can comment on that (and so the question and answer are kept separate);
  • I’m aware that I can do this via JavaScript/jQuery – but that’s not clean (IMO) as well…

2 Answers
2

I kind of feel like I’m missing something obvious, but maybe I’m not. What about the admin_notices hook, seems like the obvious choice to me. There are some admin CSS classes available you can use, like updated, error or update-nag, or you can of course add your own styles, like asked and answered here or here.

Code:

<?php
function my_cpt_info() {
    if ('edit-my_cpt' === get_current_screen()->id) {
        ?>
        <div class="updated">
            <p>
                <?php _e('Some information about my CPT...', 'my-text-domain'); ?>
            </p>
        </div>
        <?php
    }
} // function my_cpt_info
add_action('admin_notices', 'my_cpt_info');
?>

Leave a Comment