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="https://URL.../member1-220x220.jpg">

UPDATE:

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):

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

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *