Codex

Function Reference/has post thumbnail

Contents

Description

Returns a boolean if a post has a Post Thumbnail attached (true) or not (false).

Note: To enable post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file. See also Post Thumbnails.

Usage

 <?php has_post_thumbnail$post_id ); ?> 

Parameters

post_id
(integer) (optional) Post ID.
Default: 'ID', the post ID.

Examples

This example checks if there is a Post Tumbnail attached to the post. If there is no Post Thumbnail attached, show a default image. (The default image has to be uploaded to a folder called "images" in the current theme's directory.)

<?php 
//This must be in one loop

if(has_post_thumbnail()) {
	the_post_thumbnail();
} else {
	echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
}
?>

Changelog

Source File

has_post_thumbnail() is located in wp-includes/post-thumbnail-template.php.

Related

Post Thumbnails: has_post_thumbnail(), the_post_thumbnail(), get_post_thumbnail_id(), get_the_post_thumbnail(), add_image_size(), set_post_thumbnail_size()

See also index of Function Reference and index of Template Tags.