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.

Read More

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…

Related posts

2 comments

  1. 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');
    ?>
    
  2. Currently, I’m doing this:

    • hijack the bulk update message;
    • adjust the count for update;
    • insert my text;
    • hook with 0 priority.

    In code, this reads as follows:

    function my_cpt_info($messages) {
        if ('edit-my_cpt' === get_current_screen()->id) {
            global $bulk_counts;
            $bulk_counts['updated'] = 1;
    
            if (! is_array($messages))
                $messages = array();
    
            $messages['my_cpt']['updated'] = 'Whatever it is that I need to explain about this post type, I just do it right here...<br>';
    
            return $messages;
        }
    } // function my_cpt_info
    add_filter('bulk_post_updated_messages', 'my_cpt_info', 0);
    

Comments are closed.