Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there any way that I can add a short message to the custom posts type page in - ie the page where the posts are listed. I have checked the codex and searched the web to no avail.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Good question. I've often wondered it myself. This will work. You just need to change my_post_type_slug to the slug of your post type. There might be a cleaner way to find the post type other than using $_GET but it's good enough for now!

add_action('all_admin_notices', 'my_admin_notices');
function my_admin_notices() {
    if ($_GET['post_type'] == 'my_post_type_slug' ) {
    ?>
    <div>your message here</div>
    <?php
    }    
}

I'm not a full fledged wordpress guru like others here on the forum, so the way I solve these issues is look in the source of the admin, find something unique, then do a site-wide search for that text. then in whatever file I end up in, I search around for an add_action hook.

AND there is another way to do it too. But It's a hack. You can use the view_ filter which is meant to piece together an array of view options at the top of the screen. You can always output html in the hook and return the passed variable. It's a hack because they could move the position of this hook in the future and your code might not output in the right place anymore. but it's handy considering the total lack of actions in the custom post type admin head. The nice thing about this is that it outputs right after the title.

// you need to change the part after views_ to match your screen id. 
// in this example my post type slug is 'program'
add_filter('views_edit-program', 'my_view_filter_hack');
function my_view_filter_hack( $views ) {
    // output whatever you want here
    return $views; // don't forget this!
}
share|improve this answer
    
Cool, was just wondering about this last night. +1 –  Noel Tock Jan 12 '12 at 7:44
    
Thanks - but It woulnt work as it was for some reason i had to put ($wp_query->query_vars[post_type]) instead of what you had .... i actually dont know very much about arrays so maybe that's not very good code but it's working for me anyway, thanks –  byronyasgur Jan 12 '12 at 22:07
    
@byronyasgur - that's the proper way to do it. You shouldn't really use $_GET unless you have to. –  Stephen Harris Jan 13 '12 at 21:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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