How do I get the URL of a specific size featured image?

I am using <?php wp_get_attachment_thumb_url( $attachment_id ); ?> to get the url of a thumbnail for a post in WordPress. However I would like to retrieve the URL of a specific size image. So for example when displaying the post thunmbnail normally you can specify a size, like: <?php the_post_thumbnail( $size, $attr ); ?>. Is it possible to do the same with wp_get_attachment_thumb_url.

Something like: <?php wp_get_attachment_thumb_url( $attachment_id, $size ); ?>?

2 Answers
2

You want wp_get_attachment_image_src():

if ( $src = wp_get_attachment_image_src( $attachment_id, $size ) ) {
    echo $src[0]; // URL
    echo $src[1]; // Width
    echo $src[2]; // Height
}

Leave a Comment