Skip to content

Instantly share code, notes, and snippets.

@bestwebsite
Created August 11, 2017 00:21
Show Gist options
  • Save bestwebsite/0e09078119c7dd529f5467bfa9dcbefa to your computer and use it in GitHub Desktop.
Save bestwebsite/0e09078119c7dd529f5467bfa9dcbefa to your computer and use it in GitHub Desktop.
Add featured image column to WordPress admin post and page lists
add_image_size( 'bestwebsite-admin-post-featured-image', 120, 120, false );
// Add the posts and pages columns filter. They can both use the same function.
add_filter('manage_posts_columns', 'bestwebsite_add_post_admin_thumbnail_column', 2);
add_filter('manage_pages_columns', 'bestwebsite_add_post_admin_thumbnail_column', 2);
// Add the column
function bestwebsite_add_post_admin_thumbnail_column($bestwebsite_columns){
$bestwebsite_columns['bestwebsite_thumb'] = __('Featured Image');
return $bestwebsite_columns;
}
// Let's manage Post and Page Admin Panel Columns
add_action('manage_posts_custom_column', 'bestwebsite_show_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'bestwebsite_show_post_thumbnail_column', 5, 2);
// Here we are grabbing featured-thumbnail size post thumbnail and displaying it
function bestwebsite_show_post_thumbnail_column($bestwebsite_columns, $bestwebsite_id){
switch($bestwebsite_columns){
case 'bestwebsite_thumb':
if( function_exists('the_post_thumbnail') )
echo the_post_thumbnail( 'bestwebsite-admin-post-featured-image' );
else
echo 'hmm... your theme doesn\'t support featured image...';
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment