has_post_thumbnail()

You are here:

has_post_thumbnail( int|WP_Post $post = null )

Determines whether a post has an image attached.

Description Description

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.


Top ↑

Parameters Parameters

$post

(int|WP_Post) (Optional) Post ID or WP_Post object. Default is global $post.

Default value: null


Top ↑

Return Return

(bool) Whether the post has an image attached.


Top ↑

Source Source

File: wp-includes/post-thumbnail-template.php

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 );
}


Top ↑

Changelog Changelog

Changelog
Version Description
4.4.0 $post can be a post ID or WP_Post object.
2.9.0 Introduced.
Was this article helpful?
Dislike 0
Views: 10