get_the_post_thumbnail_url()WP 4.4.0

Gets the thumbnail URL specified for the post. If there is no post thumbnail, it returns false.

1 time — 0.001901 sec (very slow) | 50000 times — 18 sec (slow) | PHP 7.0.5, WP 4.4.2
Hooks from the function


String|false. Post thumbnail URL or false if no image is available. If $size does not match any registered image size, the original image URL will be returned.


get_the_post_thumbnail_url( $post, $size );
ID/object of post.
Default: current post

The name of the registered thumbnail size: thumbnail, medium, large or full, or image size as an array with width and height: [ 200, 300 ].

It’s worth to note that, if you upload a smaller image (let’s say, a 600px wide) and use this to fetch a specific larger image (let’s say, a 1920px wide for your cover), it will return the original image instead (which is smaller than what you need) instead of returning false.

If you need to fallback to another image in case the specified file doesn’t exist, you can look into wp_get_attachment_image_src() instead, and check for the width or height of the image.

Default: 'post-thumbnail'



#1 Get the URL of the post thumbnail

echo get_the_post_thumbnail_url( 6732, 'thumbnail' );

// it will return

#2 Don’t ignore the first parameter.

Proper usage of this function inside the loop:

if ( have_posts() ) :
	while ( have_posts() ) :

		// grab the url for the full size featured image
		$featured_img_url = get_the_post_thumbnail_url( get_the_ID(), 'full' );

		// link thumbnail to full size image for use with lightbox
		echo '<a href="'. esc_url( $featured_img_url ) .'" rel="lightbox">';
			the_post_thumbnail( 'thumbnail' );
		echo '</a>';


Since 4.4.0 Introduced.

get_the_post_thumbnail_url() code WP 6.5.2

function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) {
	$post_thumbnail_id = get_post_thumbnail_id( $post );

	if ( ! $post_thumbnail_id ) {
		return false;

	$thumbnail_url = wp_get_attachment_image_url( $post_thumbnail_id, $size );

	 * Filters the post thumbnail URL.
	 * @since 5.9.0
	 * @param string|false     $thumbnail_url Post thumbnail URL or false if the post does not exist.
	 * @param int|WP_Post|null $post          Post ID or WP_Post object. Default is global `$post`.
	 * @param string|int[]     $size          Registered image size to retrieve the source for or a flat array
	 *                                        of height and width dimensions. Default 'post-thumbnail'.
	return apply_filters( 'post_thumbnail_url', $thumbnail_url, $post, $size );