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.
1 Answer
Reset to default 1add_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
版权声明:本文标题:Put featured image under post title in admin area 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741255439a2366582.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
return $title . get_the_post_thumbnail('thumbnail');
? – rudtek Commented Oct 23, 2021 at 5:32the_post_thumbnail
I saidget_the_post_thumbnail
. They are 2 different things. – rudtek Commented Oct 23, 2021 at 22:52