has_post_thumbnail

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

WordPress Version: 5.6

/**
 * WordPress Post Thumbnail Template Functions.
 *
 * Support for post thumbnails.
 * Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these.
 *
 * @package WordPress
 * @subpackage Template
 */
/**
 * Determines whether a post has an image attached.
 *
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @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`.
 * @return bool Whether the post has an image attached.
 */
function has_post_thumbnail($post = null)
{
    $thumbnail_id = get_post_thumbnail_id($post);
    $has_thumbnail = (bool) $thumbnail_id;
    /**
     * Filters whether a post has a post thumbnail.
     *
     * @since 5.1.0
     *
     * @param bool             $has_thumbnail true if the post has a post thumbnail, otherwise false.
     * @param int|WP_Post|null $post          Post ID or WP_Post object. Default is global `$post`.
     * @param int|false        $thumbnail_id  Post thumbnail ID or false if the post does not exist.
     */
    return (bool) apply_filters('has_post_thumbnail', $has_thumbnail, $post, $thumbnail_id);
}

WordPress Version: 5.1

/**
 * WordPress Post Thumbnail Template Functions.
 *
 * Support for post thumbnails.
 * Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these.
 *
 * @package WordPress
 * @subpackage Template
 */
/**
 * Determines whether a post has an image attached.
 *
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @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`.
 * @return bool Whether the post has an image attached.
 */
function has_post_thumbnail($post = null)
{
    $thumbnail_id = get_post_thumbnail_id($post);
    $has_thumbnail = (bool) $thumbnail_id;
    /**
     * Filters whether a post has a post thumbnail.
     *
     * @since 5.1.0
     *
     * @param bool             $has_thumbnail true if the post has a post thumbnail, otherwise false.
     * @param int|WP_Post|null $post          Post ID or WP_Post object. Default is global `$post`.
     * @param int|string       $thumbnail_id  Post thumbnail ID or empty string.
     */
    return (bool) apply_filters('has_post_thumbnail', $has_thumbnail, $post, $thumbnail_id);
}

WordPress Version: 5.0

/**
 * WordPress Post Thumbnail Template Functions.
 *
 * Support for post thumbnails.
 * Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these.
 *
 * @package WordPress
 * @subpackage Template
 */
/**
 * Determines whether a post has an image attached.
 * 
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @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`.
 * @return bool Whether the post has an image attached.
 */
function has_post_thumbnail($post = null)
{
    return (bool) get_post_thumbnail_id($post);
}

WordPress Version: 4.4

/**
 * WordPress Post Thumbnail Template Functions.
 *
 * Support for post thumbnails.
 * Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these.
 *
 * @package WordPress
 * @subpackage Template
 */
/**
 * Check if post has an image attached.
 *
 * @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`.
 * @return bool Whether the post has an image attached.
 */
function has_post_thumbnail($post = null)
{
    return (bool) get_post_thumbnail_id($post);
}

WordPress Version: 4.2

/**
 * WordPress Post Thumbnail Template Functions.
 *
 * Support for post thumbnails.
 * Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these.
 *
 * @package WordPress
 * @subpackage Template
 */
/**
 * Check if post has an image attached.
 *
 * @since 2.9.0
 *
 * @param int $post_id Optional. Post ID.
 * @return bool Whether post has an image attached.
 */
function has_post_thumbnail($post_id = null)
{
    return (bool) get_post_thumbnail_id($post_id);
}

WordPress Version: 3.7

/**
 * WordPress Post Thumbnail Template Functions.
 *
 * Support for post thumbnails
 * Themes function.php must call add_theme_support( 'post-thumbnails' ) to use these.
 *
 * @package WordPress
 * @subpackage Template
 */
/**
 * Check if post has an image attached.
 *
 * @since 2.9.0
 *
 * @param int $post_id Optional. Post ID.
 * @return bool Whether post has an image attached.
 */
function has_post_thumbnail($post_id = null)
{
    return (bool) get_post_thumbnail_id($post_id);
}