Featured Image Column in Admin Lists
Shows a small thumbnail of the featured image next to the title in post lists, for every post type that supports featured images.
Opens WPIDE on
Code
add_action( 'admin_init', function () {
foreach ( get_post_types( array( 'show_ui' => true ) ) as $post_type ) {
if ( in_array( $post_type, array( 'attachment', 'product' ), true ) || ! post_type_supports( $post_type, 'thumbnail' ) ) {
continue;
}
add_filter( "manage_{$post_type}_posts_columns", function ( $columns ) {
$first = array_slice( $columns, 0, 1, true );
return array_merge( $first, array( 'wpide_thumb' => 'Image' ), array_slice( $columns, 1, null, true ) );
} );
add_action( "manage_{$post_type}_posts_custom_column", function ( $column, $post_id ) {
if ( 'wpide_thumb' !== $column ) {
return;
}
$thumbnail = get_the_post_thumbnail( $post_id, array( 56, 56 ) );
echo $thumbnail ? $thumbnail : '—';
}, 10, 2 );
}
} );
add_action( 'admin_head', function () {
echo '<style>.fixed .column-wpide_thumb{width:64px;}.column-wpide_thumb img{max-width:56px;height:auto;border-radius:3px;}</style>';
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.