get_the_post_thumbnail

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

WordPress Version: 6.3

/**
 * Retrieves the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
 *                           width and height values in pixels (in that order). Default 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filters the post thumbnail size.
     *
     * @since 2.9.0
     * @since 4.9.0 Added the `$post_id` parameter.
     *
     * @param string|int[] $size    Requested image size. Can be any registered image size name, or
     *                              an array of width and height values in pixels (in that order).
     * @param int          $post_id The post ID.
     */
    $size = apply_filters('post_thumbnail_size', $size, $post->ID);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filters the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param int          $post_thumbnail_id The post thumbnail ID, or 0 if there isn't one.
     * @param string|int[] $size              Requested image size. Can be any registered image size name, or
     *                                        an array of width and height values in pixels (in that order).
     * @param string|array $attr              Query string or array of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 6.2

/**
 * Retrieves the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
 *                           width and height values in pixels (in that order). Default 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filters the post thumbnail size.
     *
     * @since 2.9.0
     * @since 4.9.0 Added the `$post_id` parameter.
     *
     * @param string|int[] $size    Requested image size. Can be any registered image size name, or
     *                              an array of width and height values in pixels (in that order).
     * @param int          $post_id The post ID.
     */
    $size = apply_filters('post_thumbnail_size', $size, $post->ID);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        // Add `loading` attribute.
        if (wp_lazy_loading_enabled('img', 'the_post_thumbnail')) {
            // Get the 'loading' attribute value to use as default, taking precedence over the default from
            // `wp_get_attachment_image()`.
            $loading = wp_get_loading_attr_default('the_post_thumbnail');
            // Add the default to the given attributes unless they already include a 'loading' directive.
            if (empty($attr)) {
                $attr = array('loading' => $loading);
            } elseif (is_array($attr) && !array_key_exists('loading', $attr)) {
                $attr['loading'] = $loading;
            } elseif (is_string($attr) && !preg_match('/(^|&)loading=/', $attr)) {
                $attr .= '&loading=' . $loading;
            }
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filters the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param int          $post_thumbnail_id The post thumbnail ID, or 0 if there isn't one.
     * @param string|int[] $size              Requested image size. Can be any registered image size name, or
     *                                        an array of width and height values in pixels (in that order).
     * @param string|array $attr              Query string or array of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 6.1

/**
 * Retrieves the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
 *                           width and height values in pixels (in that order). Default 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filters the post thumbnail size.
     *
     * @since 2.9.0
     * @since 4.9.0 Added the `$post_id` parameter.
     *
     * @param string|int[] $size    Requested image size. Can be any registered image size name, or
     *                              an array of width and height values in pixels (in that order).
     * @param int          $post_id The post ID.
     */
    $size = apply_filters('post_thumbnail_size', $size, $post->ID);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        // Get the 'loading' attribute value to use as default, taking precedence over the default from
        // `wp_get_attachment_image()`.
        $loading = wp_get_loading_attr_default('the_post_thumbnail');
        // Add the default to the given attributes unless they already include a 'loading' directive.
        if (empty($attr)) {
            $attr = array('loading' => $loading);
        } elseif (is_array($attr) && !array_key_exists('loading', $attr)) {
            $attr['loading'] = $loading;
        } elseif (is_string($attr) && !preg_match('/(^|&)loading=/', $attr)) {
            $attr .= '&loading=' . $loading;
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filters the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param int          $post_thumbnail_id The post thumbnail ID, or 0 if there isn't one.
     * @param string|int[] $size              Requested image size. Can be any registered image size name, or
     *                                        an array of width and height values in pixels (in that order).
     * @param string|array $attr              Query string or array of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 5.9

/**
 * Retrieve the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
 *                           width and height values in pixels (in that order). Default 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filters the post thumbnail size.
     *
     * @since 2.9.0
     * @since 4.9.0 Added the `$post_id` parameter.
     *
     * @param string|int[] $size    Requested image size. Can be any registered image size name, or
     *                              an array of width and height values in pixels (in that order).
     * @param int          $post_id The post ID.
     */
    $size = apply_filters('post_thumbnail_size', $size, $post->ID);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        // Get the 'loading' attribute value to use as default, taking precedence over the default from
        // `wp_get_attachment_image()`.
        $loading = wp_get_loading_attr_default('the_post_thumbnail');
        // Add the default to the given attributes unless they already include a 'loading' directive.
        if (empty($attr)) {
            $attr = array('loading' => $loading);
        } elseif (is_array($attr) && !array_key_exists('loading', $attr)) {
            $attr['loading'] = $loading;
        } elseif (is_string($attr) && !preg_match('/(^|&)loading=/', $attr)) {
            $attr .= '&loading=' . $loading;
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filters the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param int          $post_thumbnail_id The post thumbnail ID, or 0 if there isn't one.
     * @param string|int[] $size              Requested image size. Can be any registered image size name, or
     *                                        an array of width and height values in pixels (in that order).
     * @param string|array $attr              Query string or array of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 5.6

/**
 * Retrieve the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
 *                           width and height values in pixels (in that order). Default 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filters the post thumbnail size.
     *
     * @since 2.9.0
     * @since 4.9.0 Added the `$post_id` parameter.
     *
     * @param string|int[] $size    Requested image size. Can be any registered image size name, or
     *                              an array of width and height values in pixels (in that order).
     * @param int          $post_id The post ID.
     */
    $size = apply_filters('post_thumbnail_size', $size, $post->ID);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param int          $post_thumbnail_id The post thumbnail ID.
         * @param string|int[] $size              Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filters the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param int          $post_thumbnail_id The post thumbnail ID.
     * @param string|int[] $size              Requested image size. Can be any registered image size name, or
     *                                        an array of width and height values in pixels (in that order).
     * @param string       $attr              Query string of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 4.9

/**
 * Retrieve the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|array $size Optional. 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'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filters the post thumbnail size.
     *
     * @since 2.9.0
     * @since 4.9.0 Added the `$post_id` parameter.
     *
     * @param string|array $size    The post thumbnail size. Image size or array of width and height
     *                              values (in that order). Default 'post-thumbnail'.
     * @param int          $post_id The post ID.
     */
    $size = apply_filters('post_thumbnail_size', $size, $post->ID);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param string       $post_thumbnail_id The post thumbnail ID.
         * @param string|array $size              The post thumbnail size. Image size or array of width
         *                                        and height values (in that order). Default 'post-thumbnail'.
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param string       $post_thumbnail_id The post thumbnail ID.
         * @param string|array $size              The post thumbnail size. Image size or array of width
         *                                        and height values (in that order). Default 'post-thumbnail'.
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filters the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param string       $post_thumbnail_id The post thumbnail ID.
     * @param string|array $size              The post thumbnail size. Image size or array of width and height
     *                                        values (in that order). Default 'post-thumbnail'.
     * @param string       $attr              Query string of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 4.6

/**
 * Retrieve the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|array $size Optional. 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'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filters the post thumbnail size.
     *
     * @since 2.9.0
     *
     * @param string|array $size The post thumbnail size. Image size or array of width and height
     *                           values (in that order). Default 'post-thumbnail'.
     */
    $size = apply_filters('post_thumbnail_size', $size);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param string       $post_thumbnail_id The post thumbnail ID.
         * @param string|array $size              The post thumbnail size. Image size or array of width
         *                                        and height values (in that order). Default 'post-thumbnail'.
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param string       $post_thumbnail_id The post thumbnail ID.
         * @param string|array $size              The post thumbnail size. Image size or array of width
         *                                        and height values (in that order). Default 'post-thumbnail'.
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filters the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param string       $post_thumbnail_id The post thumbnail ID.
     * @param string|array $size              The post thumbnail size. Image size or array of width and height
     *                                        values (in that order). Default 'post-thumbnail'.
     * @param string       $attr              Query string of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 4.4

/**
 * Retrieve the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
 * @param string|array $size Optional. 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'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string The post thumbnail image tag.
 */
function get_the_post_thumbnail($post = null, $size = 'post-thumbnail', $attr = '')
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_thumbnail_id = get_post_thumbnail_id($post);
    /**
     * Filter the post thumbnail size.
     *
     * @since 2.9.0
     *
     * @param string|array $size The post thumbnail size. Image size or array of width and height
     *                           values (in that order). Default 'post-thumbnail'.
     */
    $size = apply_filters('post_thumbnail_size', $size);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param string       $post_thumbnail_id The post thumbnail ID.
         * @param string|array $size              The post thumbnail size. Image size or array of width
         *                                        and height values (in that order). Default 'post-thumbnail'.
         */
        do_action('begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param int          $post_id           The post ID.
         * @param string       $post_thumbnail_id The post thumbnail ID.
         * @param string|array $size              The post thumbnail size. Image size or array of width
         *                                        and height values (in that order). Default 'post-thumbnail'.
         */
        do_action('end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filter the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string       $html              The post thumbnail HTML.
     * @param int          $post_id           The post ID.
     * @param string       $post_thumbnail_id The post thumbnail ID.
     * @param string|array $size              The post thumbnail size. Image size or array of width and height
     *                                        values (in that order). Default 'post-thumbnail'.
     * @param string       $attr              Query string of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 4.3

/**
 * Retrieve the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 *
 * @param int $post_id       Post ID. Default is the ID of the `$post` global.
 * @param string|array $size Optional. Registered image size to use, or flat array of height
 *                           and width values. Default 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 * @return string
 */
function get_the_post_thumbnail($post_id = null, $size = 'post-thumbnail', $attr = '')
{
    $post_id = (null === $post_id) ? get_the_ID() : $post_id;
    $post_thumbnail_id = get_post_thumbnail_id($post_id);
    /**
     * Filter the post thumbnail size.
     *
     * @since 2.9.0
     *
     * @param string $size The post thumbnail size.
     */
    $size = apply_filters('post_thumbnail_size', $size);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param string $post_id           The post ID.
         * @param string $post_thumbnail_id The post thumbnail ID.
         * @param string $size              The post thumbnail size.
         */
        do_action('begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param string $post_id           The post ID.
         * @param string $post_thumbnail_id The post thumbnail ID.
         * @param string $size              The post thumbnail size.
         */
        do_action('end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filter the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string $html              The post thumbnail HTML.
     * @param string $post_id           The post ID.
     * @param string $post_thumbnail_id The post thumbnail ID.
     * @param string $size              The post thumbnail size.
     * @param string $attr              Query string of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 4.2

/**
 * Retrieve the post thumbnail.
 *
 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size
 * is registered, which differs from the 'thumbnail' image size managed via the
 * Settings > Media screen.
 *
 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image
 * size is used by default, though a different size can be specified instead as needed.
 *
 * @since 2.9.0
 *
 * @param int $post_id       Post ID. Default is the ID of the `$post` global.
 * @param string|array $size Optional. Registered image size to use, or flat array of height
 *                           and width values. Default 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
 */
function get_the_post_thumbnail($post_id = null, $size = 'post-thumbnail', $attr = '')
{
    $post_id = (null === $post_id) ? get_the_ID() : $post_id;
    $post_thumbnail_id = get_post_thumbnail_id($post_id);
    /**
     * Filter the post thumbnail size.
     *
     * @since 2.9.0
     *
     * @param string $size The post thumbnail size.
     */
    $size = apply_filters('post_thumbnail_size', $size);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param string $post_id           The post ID.
         * @param string $post_thumbnail_id The post thumbnail ID.
         * @param string $size              The post thumbnail size.
         */
        do_action('begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param string $post_id           The post ID.
         * @param string $post_thumbnail_id The post thumbnail ID.
         * @param string $size              The post thumbnail size.
         */
        do_action('end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filter the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string $html              The post thumbnail HTML.
     * @param string $post_id           The post ID.
     * @param string $post_thumbnail_id The post thumbnail ID.
     * @param string $size              The post thumbnail size.
     * @param string $attr              Query string of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr);
}

WordPress Version: 3.7

/**
 * Retrieve Post Thumbnail.
 *
 * @since 2.9.0
 *
 * @param int $post_id Optional. Post ID.
 * @param string $size Optional. Image size. Defaults to 'post-thumbnail'.
 * @param string|array $attr Optional. Query string or array of attributes.
 */
function get_the_post_thumbnail($post_id = null, $size = 'post-thumbnail', $attr = '')
{
    $post_id = (null === $post_id) ? get_the_ID() : $post_id;
    $post_thumbnail_id = get_post_thumbnail_id($post_id);
    /**
     * Filter the post thumbnail size.
     *
     * @since 2.9.0
     *
     * @param string $size The post thumbnail size.
     */
    $size = apply_filters('post_thumbnail_size', $size);
    if ($post_thumbnail_id) {
        /**
         * Fires before fetching the post thumbnail HTML.
         *
         * Provides "just in time" filtering of all filters in wp_get_attachment_image().
         *
         * @since 2.9.0
         *
         * @param string $post_id           The post ID.
         * @param string $post_thumbnail_id The post thumbnail ID.
         * @param string $size              The post thumbnail size.
         */
        do_action('begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size);
        if (in_the_loop()) {
            update_post_thumbnail_cache();
        }
        $html = wp_get_attachment_image($post_thumbnail_id, $size, false, $attr);
        /**
         * Fires after fetching the post thumbnail HTML.
         *
         * @since 2.9.0
         *
         * @param string $post_id           The post ID.
         * @param string $post_thumbnail_id The post thumbnail ID.
         * @param string $size              The post thumbnail size.
         */
        do_action('end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size);
    } else {
        $html = '';
    }
    /**
     * Filter the post thumbnail HTML.
     *
     * @since 2.9.0
     *
     * @param string $html              The post thumbnail HTML.
     * @param string $post_id           The post ID.
     * @param string $post_thumbnail_id The post thumbnail ID.
     * @param string $size              The post thumbnail size.
     * @param string $attr              Query string of attributes.
     */
    return apply_filters('post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr);
}