get_the_post_thumbnail_url

The timeline below displays how wordpress function get_the_post_thumbnail_url has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Returns the post thumbnail URL.
 *
 * @since 4.4.0
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Registered image size to retrieve the source for or a flat array
 *                           of height and width dimensions. Default 'post-thumbnail'.
 * @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.
 */
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);
}

WordPress Version: 5.9

/**
 * Return the post thumbnail URL.
 *
 * @since 4.4.0
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Registered image size to retrieve the source for or a flat array
 *                           of height and width dimensions. Default 'post-thumbnail'.
 * @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.
 */
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);
}

WordPress Version: 5.7

/**
 * Return the post thumbnail URL.
 *
 * @since 4.4.0
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Registered image size to retrieve the source for or a flat array
 *                           of height and width dimensions. Default 'post-thumbnail'.
 * @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.
 */
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;
    }
    return wp_get_attachment_image_url($post_thumbnail_id, $size);
}

WordPress Version: 4.4

/**
 * Return the post thumbnail URL.
 *
 * @since 4.4.0
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|array $size Optional. Registered image size to retrieve the source for or a flat
 *                           array of height and width dimensions. Default 'post-thumbnail'.
 * @return string|false Post thumbnail URL or false if no URL is available.
 */
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;
    }
    return wp_get_attachment_image_url($post_thumbnail_id, $size);
}