All WordPress snippets
WordPress

Show a Thumbnail Column in the Post List Table

Adds a small featured-image preview column to the posts list in wp-admin, so you don't have to open each post to see its thumbnail.

php
/**
 * Add thumbnail column to post listing
 */
add_image_size( 'admin-list-thumb', 80, 80, false );

function wpcs_add_thumbnail_columns( $columns ) {
    if ( !is_array( $columns ) ) {
        $columns = array();
    }
    
    $new = array();

    foreach( $columns as $key => $title ) {
        if ( $key == 'title' ) { // Put the Thumbnail column before the Title column
            $new['featured_thumb'] = __( 'Image');
	}
	
        $new[$key] = $title;
    }
    
    return $new;
}

function wpcs_add_thumbnail_columns_data( $column, $post_id ) {
    switch ( $column ) {
    case 'featured_thumb':
        echo '<a href="' . $post_id . '">';
        echo the_post_thumbnail( 'admin-list-thumb' );
        echo '</a>';
        break;
    }
}

if ( function_exists( 'add_theme_support' ) ) {
    add_filter( 'manage_posts_columns' , 'wpcs_add_thumbnail_columns' );
    add_action( 'manage_posts_custom_column' , 'wpcs_add_thumbnail_columns_data', 10, 2 );
}
Want your own copy? Fork this repo and build your own snippet collection. Fork on GitHub →