0

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:

enter image description here

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.

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

1 Answer 1

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

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.