1

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...
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
  • Well, I honestly didn't think of the admin notices - simply because they are handled outside from where I looked. You are, of course, right, and this is the obvious hook/place. One problem, however, is plugins/settings that restrict (or hide etc.) admin notices for specific user( role)s. Anyway, +1, and thanks for taking care of this question.
    – tfrommen
    Feb 17 '14 at 19:12
  • 1
    My pleasure. You might be right about the restrictions/interferences by plugins, but I guess you'll have to deal with that if it actually is occurring. The only thing else I've in mind is, there is the hook all_admin_notices, which might not as well known or at least not as widely used. @tf
    – Nicolai
    Feb 17 '14 at 19:58
1

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);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.