Are you looking for a way to add the featured thumbnail to the post listing within WordPress admin? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add featured image thumbnail to admin post columns.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
add_filter('manage_posts_columns', 'posts_columns', 5); add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2); function posts_columns($defaults){ $defaults['riv_post_thumbs'] = __('Thumbs'); return $defaults; } function posts_custom_columns($column_name, $id){ if($column_name === 'riv_post_thumbs'){ echo the_post_thumbnail( 'featured-thumbnail' ); } }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress themes for travel blogs and how to use Google Optimize in WordPress.
I want a 🔗 in the media library if I don’t have an image
Is there an update on this post. I’ve added the code to my functions file where other custom functions are functioning fine and it doesn’t add anything for extra images within standard or any of the custom post types I’ve created. Any help greatly appreciated. I am running WordPress 5.2.1
When I use this code it brings my products post from woocommerce to my custom post type list.
do i add it to my wp-include/functions.php ? i am using wp4
thanks got it ! love ya !
Cool glad you got it working.
Just what i needed, thanks a lot for great snippet, and the update on how to set thumbnails size just nailed it 🙂
thank you for the snippet. its very helpful as i start to add featured images in all my post. If i like to make this custom column “sortable”, how do i go that? i know its strange to sort image, i just want to see which post do not have image.
Thanks.
Helped me a lot
Perfect code, thanks!
hi kevin
could you tell us how to reorder the e.g. 6 columns ???
thumb – titel – date – user – cont – id
to:
id- titel – user – thumb – cont – date
thanks you
This is working just fine, however the new column is appearing on all custom post type edit screens as well. How would I go about just gettting this to appear on the edit post screens and not the edit CPT screens?
Hi @5f9a29a8407e88a611b5bd004408018e:disqus I know I’m late but hoping this help other with same issue.
Try this solution
add_filter( ‘manage_edit-slider_columns’, ‘posts_columns’ ); // slider is the custom post-type you’ve created, feel free to update the post-type to which post-type you only want the custom column to display.
Hope that helps
Hi,
I’d like to do that with a custom field value (‘facebook’) would that also be possible?
Many thanks in advance!
Cheers,
Thomas.
you could just get the custom field in the normal way eg:
$custom_field = get_post_meta($post->ID, ‘facebook’, true);
then echo the result to the page eg: echo $custom_field;
@wpsnipp:disqus is right but before you can implement or call get_post_meta() function you need to add post_meta first 😉
If post-thumbnails isn’t activated for the theme, only the 1st page/post is listed, with an error in the column.
To add theme support (functions.php), this is added:
if ( function_exists( ‘add_theme_support’ ) )add_theme_support( ‘post-thumbnails’ );
What “IF” checks to see if the theme first supports post-thumbnails?
I agree ill post an updated version of this snippet.
hi, this might seem like a simple question, but where exactly do I place these snippets? functions.php?
Hi onedeep99, yes you should add this snippet to the functions.php of your wordpress theme. I just updated the post to include that little detail as I forgot to mention it.
Thank you for this great snippet. It is very useful to see if there is any thumbs in posts without opening them. Have just a few questions:
1. Is it possible to get the same feature for the pages too?
2. Is it possible to display all attached images in a post/page as thumbs instead of just one?
3. Is it possible to define in which column the they appear in. I get them in the last column in the right of the screen but the default media library displays them in the first column at the left.
Apreciate your concern 🙂
Hi Zeb,
1. yes you can ad this to pages as well just add these hooks. above the other hooks.
add_filter(‘manage_pages_columns’, ‘posts_columns’, 5);
add_action(‘manage_pages_custom_column’, ‘posts_custom_columns’, 5, 2);
2. Yes you can reorder the columns Ill post some code asap.
3. The problem with all attachments is that it may not have enough room for all attachments, Ill see if I can think of another way to display them.
Thanks alot kevin, 🙂
If there is any way to specify a number in the snippet for the thumbs to be displayed so that,if needed, a user can change the number OR any other way you might think of would also be great.
Thanks
I’m not sure I understand can you elaborate a little?
Sorry about not being clear.
However, I was thinking about a maximum number of how many thumbs to be displayed. For instance, if there is space in the admin, a user can specify max 3 or 4 images to be displayed. Otherwise, “1” could mean only the first or the featured image, even if there is several attachments.
Another way might be a kind of image rotator using any script.
I hope I have been helpful 🙂
Ahh ok I see what you mean, Ill look into this a little more could release this as a new snippet.
Great Kevin, thanks 🙂
Is there a way to do it for products?
Thanks a lot for this snippet. Very useful!
Cool glad you like the snippet, don’t forget to follow us on facebook or twitter we post new snippets daily.
hi, I’ve added those snippet but there’s a little problem though. my featured thumbnail appeared in large size (original sizes I think). could you please show me how to resize thumbnail images in admin post columns if possible. thanks.
Hi zarylnaxrie
‘featured-thumbnail’ would be a thumbnail size you created however if you replace the code on line nine above with the following.
echo the_post_thumbnail( array(100,100) );
Just change the size within the array, the follow page has more details on how post thumbnails function.
http://codex.wordpress.org/Function_Reference/the_post_thumbnail
Thank you soooooo much!!
[…] This post was mentioned on Twitter by Y Combinator Newest!, newsery5 and wp_freak, WPSNIPP. WPSNIPP said: #wordpress Add featured thumbnail to admin post columns http://bit.ly/dHuROT #blog please RT 🙂 […]