On this page
get_the_post_thumbnail_url( int|WP_Post $post = null, string|int[] $size = 'post-thumbnail' ): string|false
Returns the post thumbnail URL.
Parameters
Return
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.
Source
File: wp-includes/post-thumbnail-template.php. View all references
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 );
}
Hooks
- apply_filters( 'post_thumbnail_url',
string|false $thumbnail_url ,int|WP_Post|null $post ,string|int[] $size ) -
Filters the post thumbnail URL.
Related
Uses
| Uses | Description |
|---|---|
| wp_get_attachment_image_url() wp-includes/media.php | Gets the URL of an image attachment. |
| get_post_thumbnail_id() wp-includes/post-thumbnail-template.php | Retrieves the post thumbnail ID. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| the_post_thumbnail_url() wp-includes/post-thumbnail-template.php | Displays the post thumbnail URL. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url