admin管理员组

文章数量:1279116

Instead of inserting a new column with a featured image on it, I would like to put the featured image under the post's already existing title. I can't seem to figure out how you insert things on the title property however. Achieving this:

I've found this post: How can i place Feature Image under title field in wp-admin?

With a snippet that I can't get to work. Otherwise there are lots of solutions for adding new columns with featured images in them.

I've arrived at something like this:

add_action('admin_head-edit.php', function(){
    add_filter('the_title', function( $title, $id ) {
        return $title . get_the_post_thumbnail_url();
    }, 100, 2);
});

But if I use get_the_post_thumbnail_url the url is embedded as part of the title, and if I use the_post_thumbnail( 'thumbnail' ) it renders the image twice.

Instead of inserting a new column with a featured image on it, I would like to put the featured image under the post's already existing title. I can't seem to figure out how you insert things on the title property however. Achieving this:

I've found this post: How can i place Feature Image under title field in wp-admin?

With a snippet that I can't get to work. Otherwise there are lots of solutions for adding new columns with featured images in them.

I've arrived at something like this:

add_action('admin_head-edit.php', function(){
    add_filter('the_title', function( $title, $id ) {
        return $title . get_the_post_thumbnail_url();
    }, 100, 2);
});

But if I use get_the_post_thumbnail_url the url is embedded as part of the title, and if I use the_post_thumbnail( 'thumbnail' ) it renders the image twice.

Share Improve this question asked Oct 23, 2021 at 4:26 FluxianFluxian 1809 bronze badges 3
  • did you try return $title . get_the_post_thumbnail('thumbnail');? – rudtek Commented Oct 23, 2021 at 5:32
  • @rudtek Yes that's what I described under. Then it renders two images. – Fluxian Commented Oct 23, 2021 at 6:34
  • no, you tried the_post_thumbnail I said get_the_post_thumbnail. They are 2 different things. – rudtek Commented Oct 23, 2021 at 22:52
Add a comment  | 

1 Answer 1

Reset to default 1
add_action('admin_head-edit.php', function(){
    add_filter('the_title', function( $title, $id ) {
        return $title . the_post_thumbnail( 'thumbnail' );
    }, 100, 2);
});

Will produce 2 images because there are two titles on custom posts, apparently. One that is hidden and one that isn't. Adding the image markup to the hidden element will break the CSS that hides it. So the solution is to insert admin-css that hides it.

    .column-title .hidden ~ img{
        display: none;
    }

本文标签: Put featured image under post title in admin area