If you’re anything like me, you will write a bunch of posts and forget if you set the featured image. You may also want to log in quickly and ensure that guest posters have managed to set their own featured image. This code will add a featured image column with image preview in your ‘All Posts’ menu from the WordPress administration panel.
Once you have made the necessary modification, your admin panel will look like this:
Note the scaled featured image alongside other post details
add_image_size() Function
When an image is uploaded via the WordPress upload tool, it is automatically scaled to various dimensions as defined in your ‘Settings ► Media' administration menu. The problem with this (and its compatibility with our little function) is that we’ll reference the raw unscaled (original, larger) image… meaning that the large, unscaled image will distort the administration page. For that reason, we’ll use the WordPress the_post_thumbnail() function to create an image size of our choosing that fits nicely into our newly created featured image column. An image dimension of 60×60 seems to work well although you could choose whatever you want.
add_image_size('admin-list-thumb', 60, 60, true);
Related WordPress functions if you’re interested in further reading: add_image_size(), get_the_post_thumbnail(), get_post_thumbnail_id(), set_post_thumbnail_size(), has_post_thumbnail()
The Function
You’ll want to copy this code into your theme’s functions.php file or custom functions plugin. Download the code in a zip file below.
// Size & name of featured image
add_image_size('admin-list-thumb', 60, 60, true);
// Posts & pages columns filter
add_filter('manage_posts_columns', 'wp_add_post_thumbnail_column', 5);
add_filter('manage_pages_columns', 'wp_add_post_thumbnail_column', 5);
// Add featured image colum (we'll call it 'Featured')
function wp_add_post_thumbnail_column($cols){
$cols['wp_post_thumb'] = __('Featured');
return $cols;
}
add_action('manage_posts_custom_column', 'wp_display_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'wp_display_post_thumbnail_column', 5, 2);
// Get scaled featured-thumbnail & display it.
function wp_display_post_thumbnail_column($col, $id){
switch($col){
case 'wp_post_thumb':
if( function_exists('the_post_thumbnail') )
echo the_post_thumbnail( 'admin-list-thumb' );
else
echo 'Not supported in theme';
break;
}
}
If you’re happy to use the smallest thumbnail that WordPress creates by default (150×150), or if you’re already using smaller dimensions, you could change line 22 to echo the_post_thumbnail('thumbnail'); and delete the function to create a new image on lines 1 and 2.
|
|
Download: Featured Image in Posts Admin Panel |
If you liked this article, you may also like:


Recent Comments