WordPress at a glance

has_post_thumbnail() WP 1.0

Check if post has an image attached.

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


true/false. Whether the post has an image attached.

Works based on: get_post_thumbnail_id()
1 time = 0.000032s = very fast | 50000 times = 0.47s = very fast | PHP 7.0.5, WP 4.5.2
Hooks from the function


has_post_thumbnail( $post );
Post ID or WP_Post object.
Default: global $post

Список изменений

С версии 2.9.0 Введена.
С версии 4.4.0 $post can be a post ID or WP_Post object.

Code of has_post_thumbnail() WP 5.5.1

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 );

Related Functions

From tag: Thumbnail (images)

More from tag: Conditional tags (all)

More from category: Thumbnails

More from Template Tags: Post Thumbnails

No comments
    Log In . Register