custom post types - Add html to cpt main pageadmin edit.php

admin2025-04-19  0

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

.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

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

https://i.sstatic/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

Share Improve this question asked Aug 23, 2013 at 19:33 RizzoRizzo 2696 silver badges20 bronze badges 1
  • This can be done in JavaScript Just open source code to see the class or ID to be used. – JMau Commented Aug 23, 2013 at 20:07
Add a comment  | 

2 Answers 2

Reset to default 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.

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;
}

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745041974a281598.html

最新回复(0)