Get Image URL of WordPress Post Thumbnail Feature
24th Dec 2010 | Posted by reza | 9 CommentsIn 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[0]; // 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.
8 Comments to “Get Image URL of WordPress Post Thumbnail Feature”
Add Comments (+)-
I was looking for a way to have all the posts image in an array. I found a way to have all images with html tags, but not the pure URL of the image. And that is what I need.
-
VERY VERY THANKS FOR THIS POST.
-
Thanks., How can i use this code .
can you show example . ^^! -
thank you so much!
-
Thanks so much! :DD
-
Thanks for this post..
-
little, but helpful thins, thank you
Thanks for this post – it’s very helpful.