Add featured image thumbnail to WordPress admin columns

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.

Add a new image size

First we add a new image size. Full details for this function are found on the WordPress add_image_size() codex page.

add_image_size( 'admin-list-thumb', 100, 100, false );

If your theme already has a 100 x 100 image size, you can skip this step. If not, then you may end up with an image size that messes up the layout of the columns.

Add featured image column

Next up, we add the featured image column to the posts and pages list view and pull in the featured image itself using our newly defined image size.

// Dummy up theme support.
//add_theme_support( 'post-thumbnails' );

// Add the posts and pages columns filter. They can both use the same function.
add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
add_filter('manage_pages_columns', 'tcb_add_post_thumbnail_column', 5);

// Add the column
function tcb_add_post_thumbnail_column($cols){
  $cols['tcb_post_thumb'] = __('Featured');
  return $cols;
}

// Hook into the posts an pages column managing. Sharing function callback again.
add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);

// Grab featured-thumbnail size post thumbnail and display it.
function tcb_display_post_thumbnail_column($col, $id){
  switch($col){
    case 'tcb_post_thumb':
      if( function_exists('the_post_thumbnail') )
        echo the_post_thumbnail( 'admin-list-thumb' );
      else
        echo 'Not supported in theme';
      break;
  }
}

There is a caveat

One of the less desirable features of WordPress is that images uploaded to the media library before an image size is defined, will not have that image size available. Instead a current image size will be HTML resized. There are plugins that will fix this problem.

The eagle-eyed

Observant regular visitors may have noticed that every page and post on this site has a unique header image. I took all of them myself. Remembering which I have already used can get tricky, so I am using this very idea on my site!

Update
I have updated the code to handle themes without post-thumb support. See the codex on how to enable theme support for post thumbnails.

Update 2 – Placing the featured image in a different column position

function tcb_add_post_thumbnail_column( $cols ){
  $colsstart = array_slice( $cols, 0, 1, true );
  $colsend   = array_slice( $cols, 1, null, true );

  $colls = array_merge(
    $colsstart,
    array( 'tcb_post_thumb' => __('Featured') ),
    $colsend
  );
  return $mycolls;
}

Published by

TCBarrett

Open Source Architect (Web Geek)

11 thoughts on “Add featured image thumbnail to WordPress admin columns”

  1. I can’t seem to get this to work, I am adding it to my functions.php file but it breaks my admin area?

    1. Sorry Andy, I chopped off the final closing curly bracket. Also it breaks for themes that don’t support it. I have updated the code block. Thanks for the comment!

  2. Hi TCB,
    how can I bring the Image to the left, –> left from the title?
    Cheers,
    Denis

  3. Hi Denis

    I have amended the blog post – see “Update 2 – Placing the featured image in a different column position” for a way to ‘splice’ into the second column.

    Enjoy

  4. All this works fine. Now what if we have a custom post type and need this column only for that specific post type ? Can that be done. I want that column to be displayed only when posts of that custom type are listed.

Comments are closed.