I need to duplicate a list of thumbnails elsewhere on a page and have set up a few different custom thumbnail sizes in my functions.php file.

If I use:


Then the thumbnail gets displayed correctly, if I use:

echo get_post_thumbnail('photo-small');

Nothing gets echoed - it's an empty string.

What I am trying to do is add the generated img tags to an array so that I can loop through it outside of the loop but for some reason it's always blank.

3 Answers 3


You're using get_the_post_thumbnail() and not the nonexistent get_post_thumbnail() function, right?

As JohnG said, you have to pass the ID of the current post to get_the_post_thumbnail() (the the_post_thumbnail() function already handles that for you). The Function Reference in the WordPress Codex has many usage examples:

get_the_post_thumbnail($id);                  // without parameter -> Thumbnail

get_the_post_thumbnail($id, 'thumbnail');     // Thumbnail
get_the_post_thumbnail($id, 'medium');        // Medium resolution
get_the_post_thumbnail($id, 'large');         // Large resolution

get_the_post_thumbnail($id, array(100,100) ); // Other resolutions

Where $id is the ID of the current post. You can get it via get_the_ID().

  • Yep, that was it. What threw me was that the codex says the passing the id is optional at the top where it lists parameters; I misunderstood JohnG's response - it sounded like I only needed to include the ID if it was outside of the loop. Thanks for clearing that up
    – ollie
    Mar 16, 2012 at 11:54

dumb question, but are you calling the_post_thumbnail from within a loop? If not, then you would want to use get_post_thumbnail(), but you'd need to pass in the post_id you want the featured image for

  • Yeah I am, I have it set up in the loops so that the_post_thumbnail('photo-small') is exectued which displays the image, but then in the same loop I add $images[] = get_the_post_thumbnail('photo-large'). the_post_thumbnail('photo-large') successfully echoes it. Makes no sense to me
    – ollie
    Mar 16, 2012 at 2:03

You can pass null for id as long as it is in a loop.

get_the_post_thumbnail( null, 'large' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.