Function: get_the_post_thumbnail

get_the_post_thumbnail( integer | WP_Post $post, string | array $size, string | array $attr )

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.

Parameters

Name Type(s) Default Value Description
$post integer | WP_Post null

Optional. Post ID or WP_Post object. Default is global $post.

$size string | array 'post-thumbnail'

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'.

$attr string | array ''

Optional. Query string or array of attributes. Default empty.

Returns

string

The post thumbnail image tag.

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.