Get the Post Thumbnail URL in WordPress

John Morris
On WordPress
Published in
1 min readFeb 28, 2015

Here’s a quick one for you. This is how to get the URL only of the post thumbnail in WordPress

$thumb = wp_get_attachment_image_src( 
get_post_thumbnail_id($post->ID),
$size
);
$url = $thumb['0'];

The first function wp_get_attachment_image_src takes the $attachment_id you’re after and the $size you want.

It returns an array containing the $url, $width, $height, and a boolean if this is a re-sized image (true) or not (false).

From there you just grab $thumb[0] to get the URL.

I mainly put these here so I can refer back to them when I need them instead of searching everywhere again. But, maybe it’ll be of some use to you, as well.

John Morris is a freelance web design strategist who helps web designers master two things: 1) how to code and 2) how to market yourself so you can learn the technical skills you need and turn those skills into a full-time career.

Photo by: flickr.com/photos/dcreeves2000/

--

--

John Morris
On WordPress

I’m a web designer who helps other web designers with two things: 1) how to code and 2) how to market yourself so you can earn your living as a coder.