Will McLean is a designer and artist working in the Central Coast of NSW where he lives with his wife and 2 children.

Will is a meticulous developer and favours simplicity and clarity within his code. He can’t stand writing things twice so searches for any way to automate. His experiments can be found in the Exercises section of this site.

Will designs within systems. No project is too small for a design system. He favours the unusual, if not, how can he progress? You can read about his work in the Case Studies section of this site.

Updated: November 1, 2017

This is a Knowledge Base post.

Find the src of a particlular size of the WordPress post thumbnail

I used to add Featured Images to my wordpress templates using:

the_post_thumbnail( 'large' );

However as I now often need to use srcset to provide a list of possible images for the browser to choose from I need to find the urls of various sizes of the Featured Image. For this I use:

wp_get_attachment_image_src( $attachment_id, $size, $icon );


(integer) (required) ID of the desired attachment.
Default: None

(string/array) (optional) Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large, or full), or a 2-item array representing width and height in pixels, e.g., array(32,32).
Default: thumbnail

(bool) (optional) Use a media icon to represent the attachment.
Default: false

So to get the url of the large version of my Featured Image I use this:

$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large', false, '' );
echo $src[0];

More information can be found here: https://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src