Skip to content

Instantly share code, notes, and snippets.

@samuelguebo
Last active November 26, 2016 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samuelguebo/ab8b064f948ea6f3e7c14ef01bc27e7d to your computer and use it in GitHub Desktop.
Save samuelguebo/ab8b064f948ea6f3e7c14ef01bc27e7d to your computer and use it in GitHub Desktop.
## Add thumbnail to post columns in Dashboard
```php
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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment