Website Things

Get the Post Thumbnail URL in Wordpress

Posted on Thursday, February 14, 2013
The tag the_post_thumbnail(); is used to get the thumbnail image of the current post. When using the_post_thumbnail(); tag in Wordpress, sometimes you will need to get the actual url of the image. When outputting the_post_thumbnail(); on the page it looks like this:

To get the image path of the_post_thumbnail(); you can use this code:
$image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,’large’, true); echo $image_url[0]; 

The output will be only the path of the image and you can add your code around the image without the added tags the the_post_thumbnail(); tag adds by default.