Add html to cpt main page / admin edit.php

I want to add some html under the title of a custom post type I created. See area in image here:

http://i.stack.imgur.com/rpkV3.png

Read More

I tried using different methods including post_row_actions (depricated) filter to do this. Does anyone know of a function or a method on how to do this? I was hoping to use an action hook or filter. I want to add a simple with some instructions and maybe an image to that area.

Thanks

Related posts

2 comments

  1. You could do this by adding a notice, they appear in that spot.

    Something like this would add a notice just for pages. You would obviously need to adjust the if statement for your CPT and to show on what pages you want.

    function my_admin_notice() {
    
        global $pagenow;
    
        if (( $pagenow == 'edit.php' ) && ($_GET['post_type'] == 'page')) {
            echo '<div class="updated custom-notice"><p>My Notice</p></div>';
        }
    }
    
    add_action('admin_notices', 'my_admin_notice');
    

    You could easily add an image or whatever else you want and style it by the custom-notice class.

    enter image description here

    And technically…

    Of course you could use JS but if you just wanted to add a bit of text, you could even just use CSS. I know this won’t be a popular solution, but it is an option 🙂

    For example, creating an admin stylesheet and adding the following would add text under the Pages title. Just adjust the class post-type-page

    body.wp-admin.post-type-page .wp-heading-inline:after {
        content: "Here is some text";
        display: block;
    }
    

    enter image description here

  2. You can do this with a filter, but you have to do something you generally should not do– echo content from a filter.

    function insert_content_edit_wpse_111421($views) {
      echo '<p>This is right below the title</p>';
      return $views;
    }
    add_filter('views_edit-post','insert_content_edit_wpse_111421');
    

    That filter is not meant to be used as in the code above. It is pure chance that it is located where it need to be to pull that off, and I would not consider it stable or reliable. But it can be done.

    You probably do want to consider a Javascript solution.

Comments are closed.