Get Image URL of WordPress Post Thumbnail Feature24th Dec 2010 | Posted by reza | 9 Comments
In my recent work, I have to get image URL of post thumbnail. This is a bit difficult because WordPress doesn’t provide a function to get the URL, but only funtion to get a full HTML code. I’ll share the solution here.
Because the post thumbnail actually is an attached image to a post, you could use wp_get_attachment_image_src() to get the URL. Place the following code in the loop:
<?php $imageArray = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_name' ); $imageURL = $imageArray; // here's the image url ?>
You could replace thumbnail_name with ‘thumbnail‘, ‘medium‘, ‘large‘ or any thumbnail name you set via add_image_size function.
With this code, You’ll have more freedom to use image from WordPress thumbnail post feature.