Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to know how to get image url on the_post_thumbnail()

Default the_post_thumbnail()

<img width="800" height="533" src="http://domain.com/wp-content/uploads/2011/02/book06.jpg" class="attachment-post-thumbnail wp-post-image" alt="book06" title="book06" />

Here I want grab the src only. How do I filter the_post_thumbnail() only to get http://domain.com/wp-content/uploads/2011/02/book06.jpg

Let me know

share|improve this question
    
possible duplicate of Getting Thumbnail Path rather than Image Tag –  Jan Fabry Feb 12 '11 at 15:55

3 Answers 3

up vote 21 down vote accepted

You might also try:

If you only have one size thumbnail:

$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );

Or...if you have multiple sizes:

$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );

Found this here:
http://wpcanyon.com/tipsandtricks/get-the-src-attribute-from-wordpress-post-thumbnail/

share|improve this answer
    
A little hint: if you are using wp_get_attachment_image_src() function with size and want to get exact thumbnail size: use thumbnail name given in definition (function add_image_size()). If you use array with dimensions WP will use first image size that have proper width or height. So you may get wrong image. Example: instead of 156x98 you might have got 120x98 if you have 2 images defined: 156x98 & 120x98 (height is the same). I fell for it once ;) –  Marek Tuchalski Oct 16 '11 at 15:15

Ok got it using simplexml_load_string

$dom = simplexml_load_string(get_the_post_thumbnail());
$src = $dom->attributes()->src;
    echo $src;

Another method are welcome.

share|improve this answer

This does the trick:

<?php wp_get_attachment_image_src('subgall-thumb'); ?>

Make sure you use the correct name for the thumbnail that you are calling.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.