I added custom image size like below.

add_image_size( 'team-member', 220, 220, true );

I can get this image like below in the post.

the_post_thumbnail( 'team-member' );

But how can I get image URL if it's outside of loop. For example, is there any way to get image URL like this and use it inside shortcode?

<img src="http://URL.../member1-220x220.jpg">


For now, I'm getting it like below. Is there any better solution?

$image_extension = substr( $image, -4 );
$image = str_replace( $image_extension, '-220x220' . $image_extension, $image);

1 Answer 1


You can do this with a piece of the code from the "Post Thumbnail Linking to large Image Size" example on the get_the_post_thumbnail page (using wp_get_attachment_image_src):

$image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'team-member' );
// actual URL = $image_url[0];

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.