The add_theme_support( 'post-thumbnails' ) call back in the theme setup lesson is what turns on featured images at all — this lesson covers actually using them.
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( 'large' ); ?>
<?php endif; ?>has_post_thumbnail() checks whether one was ever set — never assume it was, an editor can always skip it. the_post_thumbnail() takes an optional size name; leaving it out uses 'thumbnail', almost never what you actually want.
| Size | Default dimensions |
|---|---|
| thumbnail | 150×150, cropped |
| medium | 300×300 max, not cropped (keeps aspect ratio) |
| large | 1024×1024 max, not cropped |
| full | The original uploaded image, unresized |
The built-in sizes rarely match a specific design exactly — a card grid might need a consistent 400×300 crop, for instance. add_image_size() registers a new one, in functions.php:
<?php
function mytheme_image_sizes() {
add_image_size( 'card-thumb', 400, 300, true );
}
add_action( 'after_setup_theme', 'mytheme_image_sizes' );The fourth argument (true) means hard crop — exactly 400×300, cropping whatever doesn't fit, rather than shrinking to fit within those dimensions while keeping the original aspect ratio.
<?php the_post_thumbnail( 'card-thumb' ); ?>New sizes don't retroactively apply
A custom size registered after images already exist only applies to newly-uploaded ones — WordPress generates every registered size at upload time, not on demand. Adding a size to an existing site with existing content usually means running the free Regenerate Thumbnails plugin once, to backfill the new crop for every already-uploaded image.
With images handled properly, the next lesson covers something that applies to everything built so far, not just images — escaping and sanitizing any data a template outputs.