10

I have a client site which accepts images from users as posts. For moderation, we are opening each draft post which obviously takes a lot of time if a hefty amount of images are moderated.

So, Is there a way to show featured images of the post on the admin post list page as a column?

0

4 Answers 4

13

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.

0
14

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

10
  • nothing to display
    – busyjax
    Commented Aug 22, 2013 at 16:20
  • Are you sure your post has featured image? Can you show me one screenshot? This code works fine for me. Commented Aug 22, 2013 at 18:22
  • i.imgur.com/UM67XYl.jpg here it is
    – busyjax
    Commented Aug 22, 2013 at 18:41
  • I asked you to show screenshot of featured image in single post. Where you have uploaded it. i.e mervin.info/wp-content/uploads/2012/03/screenshot-1-300x209.png Commented Aug 22, 2013 at 20:49
  • 1
    I had to change to the second function to the following: echo get_the_post_thumbnail($post_id, 'thumbnail'); return true;
    – PNMG
    Commented Jun 9, 2014 at 19:39
6

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;
}
2
  • Man thank you, this is a really good implementation. Commented Apr 5, 2019 at 20:52
  • Hy Otinane, is there any chance this only be apply to "Post Entries" and not to the rest of the custom posts type! Commented Apr 17, 2019 at 0:04
2

This code shows how to add the featured image column to a 'books' custom post type (CPT). Replace in the first line word 'books' with the slug of your custom post type.

add_filter('manage_books_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;
}

You can find more information here https://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.