the_post_thumbnail_url()
Display the post thumbnail URL.
1 time — 0.002188 sec (very slow) | 50000 times — 17.96 sec (slow) | PHP 7.0.5, WP 4.4.2
No Hooks.
Return
null
. Nothing (null).
Usage
the_post_thumbnail_url( $size );
- $size(string|int[])
- Image size to use. Accepts any valid image size, or an array of width and height values in pixels (in that order).
Default: 'post-thumbnail'
Examples
#1 Display the URL of the post thumbnail
the_post_thumbnail_url( 'thumbnail' ); // outputs // http://example.com/wp-content/uploads/2016/03/post-meta-fields4-80x80.png
#2 Background thumbnail for DIV element
<div class="post" style="background-image: url(<?php the_post_thumbnail_url(); ?>)"></div>
Changelog
Since 4.4.0 | Introduced. |
the_post_thumbnail_url() the post thumbnail url code WP 6.6.2
function the_post_thumbnail_url( $size = 'post-thumbnail' ) { $url = get_the_post_thumbnail_url( null, $size ); if ( $url ) { echo esc_url( $url ); } }