IMPORTANT PLEASE READ!
Website development and design blog, tutorials and inspiration

Adding Featured Image To WordPress All Posts Screen

Easily see post thumbnails in the WordPress admin post listings

By , Written on in PHP

Adding Featured Image To WordPress All Posts Screen

217 words, estimated reading time 1 minutes.

This tutorial will show you how to add a Featured Image thumbnail to the "All Posts" admin screen which is useful to see what posts haven't got a thumbnail set, or for checking thumbnails quickly.

The featured image thumbnail is added by hooking into the manage_posts_columns action. This action maintains a list of the columns, to add or remove columns, you just need to add or remove the entry from the array. The following snippet will add an Image column to the end of the table. To insert an item at a specific place, you have to use PHP's array_splice function to insert the item.

Featured Image Thumbnail on Post Listings
Featured Image Thumbnail on Post Listings
  1. function custom_columns($columns)
  2. {
  3. $columns['featured_image'] = 'Image';
  4. return $columns;
  5. }
  6. add_filter('manage_posts_columns' , 'custom_columns');

Now that WordPress knows about the column, we have to add another function to display the image. This is done using the manage_posts_custom_column action. This action runs for each column, and a check on the column allows you to specify the data output. In this case, we are only adding one column, but you can add to it by simply extending the switch statement.

  1. function custom_columns_data($column, $post_id)
  2. {
  3. switch ( $column )
  4. {
  5. case 'featured_image':
  6. echo the_post_thumbnail('thumbnail');
  7. break;
  8. }
  9. }
  10. add_action('manage_posts_custom_column', 'custom_columns_data', 10, 2);

Add these code blocks to your themes functions.php or your plugin file and the featured image will be shown on the WordPress admin post listings pages.

Last updated on: Tuesday 20th June 2017

Did you Like this Post? Why not Like us on Facebook?

 

Further Reading
Comments

There are no comments for this post. Be the first!

Leave a Reply

Your email address will not be published.