Show featured image in admin posts and pages table

Davor Mlinarić
16 May 2022

Sometimes is usefull to see if some post or page have feature image or not, this code will add small image at end of tables in admin pages and posts sections. It register new image size 120×120 that is used in this case.

add_image_size( 'webbox-admin-post-featured-image', 120, 120, false );

add_filter('manage_posts_columns', 'webbox_add_post_admin_thumbnail_column', 2);
add_filter('manage_pages_columns', 'webbox_add_post_admin_thumbnail_column', 2);


function webbox_add_post_admin_thumbnail_column($webbox_columns){
    $webbox_columns['webbox_thumb'] = __('Featured image');
    return $webbox_columns;
}

add_action('manage_posts_custom_column', 'webbox_show_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'webbox_show_post_thumbnail_column', 5, 2);

function webbox_show_post_thumbnail_column($webbox_columns, $webbox_id){
    switch($webbox_columns){
        case 'webbox_thumb':
        if( function_exists('the_post_thumbnail') ) {
            echo the_post_thumbnail( 'webbox-admin-post-featured-image' );
        }
        else
            echo 'no image!';
        break;
    }
}
s (1)

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy