In the WordPress admin, the Posts and Pages lists show titles, authors and dates, but not whether a post has a featured image. Finding the posts without one means opening them one by one.
This snippet adds an Image column to the admin list of posts, pages and every other post type that supports featured images. It shows a small 60px preview, or a dash when there is no featured image.
The snippet
<?php
/**
* Show the featured image in the WordPress admin lists of posts, pages and other post types.
*/
add_filter( 'manage_posts_columns', 'dpc_thumb_column', 10, 2 );
add_filter( 'manage_pages_columns', 'dpc_thumb_column' );
function dpc_thumb_column( $columns, $post_type = 'page' ) {
if ( ! post_type_supports( $post_type, 'thumbnail' ) ) {
return $columns;
}
// Put the image column right after the checkbox, before the title.
$new = array();
foreach ( $columns as $key => $label ) {
$new[ $key ] = $label;
if ( 'cb' === $key ) {
$new['dpc_thumb'] = esc_html__( 'Image', 'dpc' );
}
}
if ( ! isset( $new['dpc_thumb'] ) ) {
$new['dpc_thumb'] = esc_html__( 'Image', 'dpc' );
}
return $new;
}
add_action( 'manage_posts_custom_column', 'dpc_thumb_column_cell', 10, 2 );
add_action( 'manage_pages_custom_column', 'dpc_thumb_column_cell', 10, 2 );
function dpc_thumb_column_cell( $column, $post_id ) {
if ( 'dpc_thumb' !== $column ) {
return;
}
$thumb_id = get_post_thumbnail_id( $post_id );
if ( ! $thumb_id ) {
echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . esc_html__( 'No featured image', 'dpc' ) . '</span>';
return;
}
// array( 60, 60 ) reuses an existing size (usually "thumbnail"), so no extra image size is generated.
echo wp_get_attachment_image( $thumb_id, array( 60, 60 ), false, array( 'alt' => '' ) );
}
add_action( 'admin_enqueue_scripts', 'dpc_thumb_column_css' );
function dpc_thumb_column_css( $hook_suffix ) {
if ( 'edit.php' !== $hook_suffix ) {
return;
}
wp_register_style( 'dpc-thumb-column', false, array(), '1.0' );
wp_enqueue_style( 'dpc-thumb-column' );
wp_add_inline_style(
'dpc-thumb-column',
'.fixed .column-dpc_thumb { width: 60px; } .column-dpc_thumb img { display: block; width: 60px; height: 60px; object-fit: cover; border-radius: 2px; }'
);
}
Add it with Scripts Organizer
In Scripts Organizer go to Code Blocks → Add New and give the block a name. Set Trigger location to Admin only, tick PHP under Script location, paste the code into the PHP editor and publish. Leave Action/Hook empty.
The list tables only exist in wp-admin, so the code does not need to load on the front end. Admin only also covers Quick Edit, which saves through admin-ajax.php and redraws the row with the column.
The same code also works unchanged in a small plugin or an mu-plugin.
How it works
manage_posts_columnsruns for every post type except pages and passes the post type;manage_pages_columnsruns for pages. The column is only added when the post type supportsthumbnail.- The column is inserted right after the checkbox, so the image sits next to the title.
manage_posts_custom_columnandmanage_pages_custom_columnprint the cell.wp_get_attachment_image()builds an escaped<img>tag withsrcsetand lazy loading.- The size
array( 60, 60 )makes WordPress pick the smallest existing image size that fits, usually the 150px thumbnail. The older version registered a new 120×120 image size, which WordPress then generated for every upload on the site. - A few lines of CSS, loaded only on list screens (
edit.php), keep the column narrow and crop the preview to a square.
Customise it
- Column at the end: delete the
foreachloop and return$columns + array( 'dpc_thumb' => esc_html__( 'Image', 'dpc' ) ). - Bigger preview: change
60in the size array and in the CSS. - Only posts: delete the
manage_pages_columnsandmanage_pages_custom_columnlines. - More columns: see Add Taxonomy to Admin columns.
Gotchas
- Some post types, such as WooCommerce products, already show their own image column. You then see two images; skip them by checking
'product' === $post_typeat the top ofdpc_thumb_column(). - The column cannot be sorted, because WordPress cannot order posts by an image.
- Hide it per user under Screen Options at the top of the list.
In the Scripts Organizer library Import it with one click from Scripts Organizer.