Last active
November 26, 2016 21:35
-
-
Save samuelguebo/ab8b064f948ea6f3e7c14ef01bc27e7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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