How To Add A Featured Image To WordPress All Posts Screen

How to show the featured image to WordPress

By Tim TrottWordPress • May 16, 2014
How To Add A Featured Image To WordPress All Posts Screen

Featured images, or Post Thumbnails, symbolise a specific Post, Page, or Custom Post Type. When you design your theme, you can include the featured image in various places, such as your archive page, header, or above a post in a header.

Featured Image Thumbnail on Post Listings
Featured Image Thumbnail on Post Listings

Enable Featured Image Support

Before the Featured Image interface will be shown on the Edit screen, themes must declare support for the Featured Image function. Support is declared in your theme's functions.php file by including the following code:

php
add_theme_support('post-thumbnails');

When you enable Featured Images support, the Featured Image meta box will appear on the Edit screens for the relevant content item. You can enable it in the screen settings if you cannot see it. The Featured Image meta box is displayed by default in the sidebar of the Edit Post and Edit Page screens.

Adding Featured Image Column to WordPress All Posts View

The featured image thumbnail is added by hooking into the manage_posts_columns action. This action maintains a list of the columns; you need to add or remove the entry from the array to add or remove columns. 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.

php
function custom_columns($columns) 
{
  $columns['featured_image'] = 'Image';
  return $columns;
}
add_filter('manage_posts_columns' , 'custom_columns');

Now that WordPress knows about the column, we must 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 extending the switch statement.

php
function custom_columns_data($column, $post_id)
{
  switch ( $column ) 
  {
    case 'featured_image':
        echo the_post_thumbnail('thumbnail');
        break;
  }
}
add_action('manage_posts_custom_column', 'custom_columns_data', 10, 2);

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

About the Author

Tim Trott is a senior software engineer with over 20 years of experience in designing, building, and maintaining software systems across a range of industries. Passionate about clean code, scalable architecture, and continuous learning, he specialises in creating robust solutions that solve real-world problems. He is currently based in Edinburgh, where he develops innovative software and collaborates with teams around the globe.

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

My website and its content are free to use without the clutter of adverts, popups, marketing messages or anything else like that. If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

There are no comments yet. Why not get the discussion started?

New comments for this post are currently closed.