WordPress Thumbnails

Definition
Definition
A thumbnail in WordPress is the featured image of a post. In the editor you set it in the Featured image box. In code it is called a post thumbnail.
Your theme shows it on blog lists, single posts, and cards. The usual pattern is to check with has_post_thumbnail(), then print it with the_post_thumbnail().
Three steps.1) Enable it with add_theme_support( 'post-thumbnails' ). 2) Set the image in the post editor. 3) Check and print it in your template.
Syntax
Syntax
Enable the feature once, then check and show the image.
<?php
// functions.php
add_theme_support( 'post-thumbnails' );
// single.php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'large' );
}
Reference
Which Function to Use
Four functions cover almost everything. The ones that start with get_ return a value. The others print.
Always check with has_post_thumbnail() before you print any wrapper HTML. This avoids empty tags on posts that have no featured image.
Reference
Image Sizes
Pass a size to the_post_thumbnail() or get_the_post_thumbnail(). You can use a name or an array of width and height.
| Size | What it means |
|---|
'thumbnail' | Small square image. Default 150 x 150, cropped. Set in Settings > Media. |
'medium' | Default max 300 x 300. Keeps the shape of the image. |
'large' | Default max 1024 x 1024. Keeps the shape of the image. |
'full' | The original image you uploaded. |
'post-thumbnail' | The theme's own size. A theme sets it with set_post_thumbnail_size(). This is the default. |
array( 300, 200 ) | A custom width and height in pixels. WordPress picks the closest image size. |
Theme size.A theme sets its default size with set_post_thumbnail_size( 1200, 630, true ) in functions.php. That size is what 'post-thumbnail' means.
Code
WordPress Examples
Two short examples with sample output.
Example 1 — Check, then show the image
Print the featured image only if the post has one.
<?php if ( has_post_thumbnail() ) : ?>
<div class="post-image">
<?php the_post_thumbnail( 'medium' ); ?>
</div>
<?php endif; ?>
<div class="post-image">
<img width="300" height="200" src="https://example.com/wp-content/uploads/2026/11/photo-300x200.jpg" class="attachment-medium size-medium wp-post-image" alt="" decoding="async" />
</div>
How It Works
has_post_thumbnail() returns true when a featured image is set.the_post_thumbnail( 'medium' ) prints the image at the medium size.- If there is no image, the
div is skipped.
Example 2 — Return the image and wrap it
Use the get_ twin to put the image inside a link.
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>">
<?php echo get_the_post_thumbnail( null, 'medium' ); ?>
</a>
<?php endif; ?>
<a href="https://example.com/hello-world/">
<img width="300" height="200" src="https://example.com/wp-content/uploads/2026/11/photo-300x200.jpg" class="attachment-medium size-medium wp-post-image" alt="" decoding="async" />
</a>
How It Works
get_the_post_thumbnail() returns the img tag as a string.echo prints it inside the a tag.- Use
the_post_thumbnail() when you do not need to wrap the image.
Continue
Next: WordPress Thumbnail Functions
Now that you know the basics, open the functions index for all four guides.
Full list: WordPress Thumbnail Functions index (/wordpress/thumbnail/function).
Frequently Asked Questions
It is the featured image of a post. WordPress calls it a post thumbnail in code and a featured image in the editor.
Add add_theme_support( 'post-thumbnails' ) in your theme functions.php. Then the Featured image box shows in the post editor.
Check with has_post_thumbnail(), then print it with the_post_thumbnail().
the_post_thumbnail() prints the image. get_the_post_thumbnail() returns it as a string so you can wrap it in your own HTML.
thumbnail, medium, large, full, the theme size post-thumbnail, a custom size from add_image_size(), or an array of width and height.
Open the WordPress Thumbnail Functions index. It lists all four guides in short tables.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful