WordPress V5.0+Template Tag Reference Guide as of Version 5.2
Presented by DBS > Interactive Development :
Post Thumbnail Tags
Get Post Thumbnail IDget_post_thumnbnail_id();
If a thumbnail is set - Returns the ID of the Thumbnail attached to the post. If no such attachment exists, the function returns null (empty value).
<?php get_post_thumnbnail_id($id); ?>
$id
Integer • Default: none
(Optional) Post ID.
Get The Post Thumbnailget_the_post_thumnbnail();
Gets Post Thumbnail as set in post's or page's edit screen. Thumbnail images are given class "attachment-thumbnail".
<?php get_post_thumnbnail_id($id, $size, $attr); ?>
$id
Integer • Default: none
(Optional) Post ID.
$size
String • Default: 'post-thumbnail'
(Optional) Image size.
$attr
String/Array •
(Optional) Query string or array of attributes. See wp_get_attachment_image.
<?php $default_attr = array( | ||
'src' | => | $src, |
'class' | => | "attachment-$size", |
'alt' | => | trim(strip_tags( $attachment->post_excerpt )), |
'title' | => | trim(strip_tags( $attachment->post_title )), |
); | ||
?> |
Has Post Thumbnailhas_post_thumbnail();
Returns a boolean if post has an image 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.
<?php has_post_thumbnail($post_id); ?>
$post_id
Integer • Default: 'ID', the post ID
(Optional) Post ID.
The Post Thumbnailthe_post_thumbnail();
Display Post Thumbnail as set in post's edit screen. Thumbnail images are given class "attachment-thumbnail". To enable post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file.
<?php the_post_thumbnail($size, $attr); ?>
$size
String/Array • Default: 'post-thumbnail', which theme sets using set_post_thumbnail_size($width, $height, $crop_flag);
(Optional) Image size. Either a string keyword(thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32).
$attr
Array • Default: none
(Optional) Array of attribute/value pairs. For details, search source for the function that the_post_thumbnail relies on: wp_get_attachment_image.