How do I get image url only on the_post_thumbnail

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

Default the_post_thumbnail()

<img width="800" height="533" src="https://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

6

You might also try:

If you only have one size thumbnail:

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

Or…if you have multiple sizes:

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

Note that wp_get_attachment_image_src() returns an array: url, width, height, is_intermediate.

So if you just want only the image url:

echo $thumbnail[0];

Resources:

  • http://wpcanyon.com/tipsandtricks/get-the-src-attribute-from-wordpress-post-thumbnail/
  • https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

Leave a Comment