1

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

https://i.sstatic.net/rpkV3.png

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

1
  • This can be done in JavaScript Just open source code to see the class or ID to be used.
    – JMau
    Aug 23, 2013 at 20:07

2 Answers 2

2

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

1

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.

2
  • Thanks. What would be the best way to do this in JS?
    – Rizzo
    Aug 26, 2013 at 14:35
  • views_edit-post is a variable filter. views_edit- plus your CPT slug should do it.
    – s_ha_dum
    Aug 26, 2013 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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