add featured image thumbnail to WordPress admin columns


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



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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.