Add featured image thumbnail to WordPress admin columns


/ Published in: PHP
Save to your folder(s)

The admin pages listing the site’s posts and pages come with various text columns (title, tags, categories, author and so on). In order to see what the featured images are, you have to visit each post or page individually. What I will show here, is how to get add a column with a reasonably sized thumbnail copy of the featured image. Please note that this only works for themes that support featured images.


Copy this code and paste it in your HTML
  1. /**
  2.  *----------------- Add Featured Images to Page List Views in Admin Area -------------------
  3. **/
  4.  
  5. // Add the posts and pages columns filter. They can both use the same function.
  6. add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
  7. add_filter('manage_pages_columns', 'tcb_add_post_thumbnail_column', 5);
  8.  
  9. // Add the column
  10. function tcb_add_post_thumbnail_column($cols){
  11. $cols['tcb_post_thumb'] = __('Featured');
  12. return $cols;
  13. }
  14.  
  15. // Hook into the posts an pages column managing. Sharing function callback again.
  16. add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
  17. add_action('manage_pages_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
  18.  
  19. // Grab featured-thumbnail size post thumbnail and display it.
  20. function tcb_display_post_thumbnail_column($col, $id){
  21. switch($col){
  22. case 'tcb_post_thumb':
  23. if( function_exists('the_post_thumbnail') )
  24. echo the_post_thumbnail( 'admin-list-thumb' );
  25. else
  26. echo 'Not supported in theme';
  27. break;
  28. }
  29. }

URL: http://www.tcbarrett.com/2011/10/add-featured-image-thumbnail-to-wordpress-admin-columns/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.