Retrieve featured image as object

First get the registered image sizes and the featured image attachment id:

$sizes = get_intermediate_image_sizes();
$post_thumbnail_id = get_post_thumbnail_id();

Loop through the registered sizes and create an array:

$images = array();
foreach ( $sizes as $size ) {
    $images[] = wp_get_attachment_image_src( $post_thumbnail_id, $size );
}

Combined as a function to place inside functions.php:

function get_all_image_sizes($attachment_id = 0) {
    $sizes = get_intermediate_image_sizes();
    if(!$attachment_id) $attachment_id = get_post_thumbnail_id();

    $images = array();
    foreach ( $sizes as $size ) {
        $images[] = wp_get_attachment_image_src( $attachment_id, $size );
    }

    return $images;
}

Usage:

$featured_image_sizes = get_all_image_sizes();

Leave a Comment