Wordpress - How do I get image url only on the_post_thumbnail

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/

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.


Since WordPress 4.4, there's an efficient core function that can handle this in a cleaner way than the answers here.

You can use the_post_thumbnail_url( $size ) which will print the URL of the post thumbnail.

Alternatively if you want to return the URL instead of immediately output it, you can use $url = get_the_post_thumbnail_url( $post_id, $size )