Solution
My previous post was How To Use The Post Thumbnail In WordPress 2.9 so if you aren’t familiar with post thumbnail feature WordPress has read that post first.
Here is a little snippet to get the SRC attribute of the post thumbnail.
$thumbnail = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post->ID ));
$thumbnail will be an array holding the link, the width and the height, so to get the link use $thumbnail[0].
If you have multiple thumbnail sizes (specified using add_image_size()) you can use the code bellow to get the proper image, just change size with the proper image size name.
$thumbnail = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post->ID ), "size");
Updated
Thanks to ralle (from the comments bellow) for this solution
Our WordPress themes
We have a few WordPress themes that we would like you to take a look at if you want.
check out the portfolio











Thanks!!!!! Saved my time
You’re welcome
Thx !! pretty useful !!!!
Thanks!
I need to get the title of the thumbnail and I didn’t find the way. With this I changed ‘src’ for ‘title’ and works great!
Thanks again for shearing the function!
Helped very much!
Great job, thx.
Thanks! I was looking everywhere for this and couldn’t figure it out on my own
Thanks for code.
However when I try this I am only able to link to the actually src of the thumbnail (feature image) which is 150px y 150px. (src=”http://www.domain.com/wp-content/uploads/2010/07/1-150×150.jpg”)
How can I make this link to the original image which is 1000px by 750px? (src=”http://www.domain.com/wp-content/uploads/2010/07/1.jpg”).
Thanks
@Amin – get_the_post_thumbnail() accepts 2 parameters, one of them is the size you need. Take a look at http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
I see. Thanks!
My final code just for reference is::
$thumb = get_the_post_thumbnail($post->ID, $size);
$pattern= “/(?<=src=['|\"])[^'|\"]*?(?=['|\"])/i";
preg_match($pattern, $thumb, $thePath);
$theSrc = $thePath[0];
echo "“.get_the_post_thumbnail($post->ID,array(640,9999)).”“;
Thanks just what i needed, i should really brush up on regular expressions i never thought of using one i just spent my time futily looking for a way to get the src from a wp function.
You do not have to use regex – try out this solution:
$thumbnail = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post->ID ), $size );
ralle’s right you don’t need regex
to print the src echo $thumbnail[0];
genius ralle, thanks!
@ralle – Thanks, updated the post.
@petergibbons – Yup, updated.