wordpress snippets last updated   : April 14, 2014
we now have 630 snippets

Add featured thumbnail to admin post columns

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will add the featured thumbnail to the post listing within the wordpress admin. This is a featured I added to my theme so that when creating posts I could more easily see what posts I had added thumbnails to.

snippet :  PHPcopy
add_filter('manage_posts_columns', 'posts_columns', 5);
add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2);
function posts_columns($defaults){
    $defaults['riv_post_thumbs'] = __('Thumbs');
    return $defaults;
}
function posts_custom_columns($column_name, $id){
	if($column_name === 'riv_post_thumbs'){
        echo the_post_thumbnail( 'featured-thumbnail' );
    }
}

  • Pingback: Tweets that mention Wordpress Add featured thumbnail to admin post columns – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com

  • http://twitter.com/zarylnaxrie zarylnaxrie

    hi, I’ve added those snippet but there’s a little problem though. my featured thumbnail appeared in large size (original sizes I think). could you please show me how to resize thumbnail images in admin post columns if possible. thanks.

    • http://wpsnipp.com Kevin Chard

      Hi zarylnaxrie
      ‘featured-thumbnail’ would be a thumbnail size you created however if you replace the code on line nine above with the following.

      echo the_post_thumbnail( array(100,100) );

      Just change the size within the array, the follow page has more details on how post thumbnails function.

      http://codex.wordpress.org/Function_Reference/the_post_thumbnail

  • http://cityheadache.net Corinne

    Thanks a lot for this snippet. Very useful!

    • http://wpsnipp.com Kevin Chard

      Cool glad you like the snippet, don’t forget to follow us on facebook or twitter we post new snippets daily.

  • zeb

    Thank you for this great snippet. It is very useful to see if there is any thumbs in posts without opening them. Have just a few questions:

    1. Is it possible to get the same feature for the pages too?
    2. Is it possible to display all attached images in a post/page as thumbs instead of just one?
    3. Is it possible to define in which column the they appear in. I get them in the last column in the right of the screen but the default media library displays them in the first column at the left.

    Apreciate your concern :)

    • http://wpsnipp.com Kevin Chard

      Hi Zeb,
      1. yes you can ad this to pages as well just add these hooks. above the other hooks.

      add_filter(‘manage_pages_columns’, ‘posts_columns’, 5);
      add_action(‘manage_pages_custom_column’, ‘posts_custom_columns’, 5, 2);

      2. Yes you can reorder the columns Ill post some code asap.
      3. The problem with all attachments is that it may not have enough room for all attachments, Ill see if I can think of another way to display them. 

      • zeb

        Thanks alot kevin, :)
        If there is any way to specify a number in the snippet for the thumbs to be displayed so that,if needed, a user can change the number OR any other way you might think of would also be great.
        Thanks

        • http://wpsnipp.com Kevin Chard

          I’m not sure I understand can you elaborate a little?

        • zeb

          Sorry about not being clear.
          However, I was thinking about a maximum number of how many thumbs to be displayed. For instance, if there is space in the admin, a user can specify max 3 or 4 images to be displayed. Otherwise, “1″ could mean only the first or the featured image, even if there is several attachments.
          Another way might be a kind of image rotator using any script.
          I hope I have been helpful :)

        • http://wpsnipp.com Kevin Chard

          Ahh ok I see what you mean, Ill look into this a little more could release this as a new snippet.

        • zeb

          Great Kevin, thanks :)

  • onedeep99

    hi, this might seem like a simple question, but where exactly do I place these snippets? functions.php?

    • http://wpsnipp.com Kevin Chard

      Hi onedeep99, yes you should add this snippet to the functions.php of your wordpress theme. I just updated the post to include that little detail as I forgot to mention it.

  • http://www.cliffpaulick.com Cliff Paulick

    If post-thumbnails isn’t activated for the theme, only the 1st page/post is listed, with an error in the column.
    To add theme support (functions.php), this is added:
    if ( function_exists( ‘add_theme_support’ ) )add_theme_support( ‘post-thumbnails’ );

    What “IF” checks to see if the theme first supports post-thumbnails?

    • http://wpsnipp.com Kevin Chard

      I agree ill post an updated version of this snippet.

  • Thomas

    Hi,

    I’d like to do that with a custom field value (‘facebook’) would that also be possible?

    Many thanks in advance!

    Cheers,
    Thomas.

    • http://wpsnipp.com Kevin Chard

      you could just get the custom field in the normal way eg:
      $custom_field = get_post_meta($post->ID, ‘facebook’, true);

      then echo the result to the page eg: echo $custom_field;

    • http://www.sutanaryan.com/ Ryan S

      @wpsnipp:disqus is right but before you can implement or call get_post_meta() function you need to add post_meta first ;)

  • derek

    This is working just fine, however the new column is appearing on all custom post type edit screens as well. How would I go about just gettting this to appear on the edit post screens and not the edit CPT screens?

    • http://www.sutanaryan.com/ Ryan S

      Hi @5f9a29a8407e88a611b5bd004408018e:disqus I know I’m late but hoping this help other with same issue.

      Try this solution
      add_filter( ‘manage_edit-slider_columns’, ‘posts_columns’ ); // slider is the custom post-type you’ve created, feel free to update the post-type to which post-type you only want the custom column to display.

      Hope that helps

  • diljan

    hi kevin

    could you tell us how to reorder the e.g. 6 columns ???

    thumb – titel – date – user – cont – id
    to:
    id- titel – user – thumb – cont – date

    thanks you

  • Sergey Trushin

    Perfect code, thanks!

  • Farzanmc

    Thanks.
    Helped me a lot

  • Ed

    thank you for the snippet. its very helpful as i start to add featured images in all my post. If i like to make this custom column “sortable”, how do i go that? i know its strange to sort image, i just want to see which post do not have image.

jqsnipp.com | we just launched jquery snippets website