Wordpress - Post featured image column on admin post list page
This is what I'm using, cobbled together from snippets found online... It's uses a filter on manage_posts_colummns
to re-jig the headers and an action on manage_posts_custom_column
to add the row level data.
function custom_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'featured_image' => 'Image',
'title' => 'Title',
'comments' => '<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>',
'date' => 'Date'
);
return $columns;
}
add_filter('manage_posts_columns' , 'custom_columns');
function custom_columns_data( $column, $post_id ) {
switch ( $column ) {
case 'featured_image':
the_post_thumbnail( 'thumbnail' );
break;
}
}
add_action( 'manage_posts_custom_column' , 'custom_columns_data', 10, 2 );
You can also use this on custom post types by filtering on manage_CPTNAME_posts_columns
.
Use this hook to add custom column to admin post/page list view.
add_filter('manage_posts_columns', 'add_img_column');
add_filter('manage_posts_custom_column', 'manage_img_column', 10, 2);
function add_img_column($columns) {
$columns['img'] = 'Featured Image';
return $columns;
}
function manage_img_column($column_name, $post_id) {
if( $column_name == 'img' ) {
echo get_the_post_thumbnail($post_id, 'thumbnail');
}
return $column_name;
}
Put this code in your functions.php
Based on @Mangesh Parte code, you can have featured image at first column, before title.
add_filter('manage_posts_columns', 'add_img_column');
add_filter('manage_posts_custom_column', 'manage_img_column', 10, 2);
function add_img_column($columns) {
$columns = array_slice($columns, 0, 1, true) + array("img" => "Featured Image") + array_slice($columns, 1, count($columns) - 1, true);
return $columns;
}
function manage_img_column($column_name, $post_id) {
if( $column_name == 'img' ) {
echo get_the_post_thumbnail($post_id, 'thumbnail');
}
return $column_name;
}