Add Featured Image Column to Posts List
Inserts a thumbnail preview column before the Title column in the wp-admin Posts list table.
PHPby SnipCraft
php
<?php
add_filter( 'manage_posts_columns', 'scseed_add_thumbnail_column' );
function scseed_add_thumbnail_column( $columns ) {
$new = array();
foreach ( $columns as $key => $value ) {
if ( 'title' === $key ) {
$new['scseed_thumb'] = __( 'Image' );
}
$new[ $key ] = $value;
}
return $new;
}
add_action( 'manage_posts_custom_column', 'scseed_render_thumbnail_column', 10, 2 );
function scseed_render_thumbnail_column( $column_name, $post_id ) {
if ( 'scseed_thumb' !== $column_name ) {
return;
}
if ( has_post_thumbnail( $post_id ) ) {
echo get_the_post_thumbnail( (int) $post_id, array( 60, 60 ) );
} else {
echo '<span aria-hidden="true">—</span>';
}
}
add_action( 'admin_head', 'scseed_thumbnail_column_style' );
function scseed_thumbnail_column_style() {
$screen = get_current_screen();
if ( $screen && 'edit-post' === $screen->id ) {
echo '<style>.column-scseed_thumb{width:70px;}</style>';
}
}#admin#columns#featured-image#posts