How to regenerate thumbnails in WordPress?
To regenerate thumbnails in WordPress, you can install the free Regenerate Thumbnails plugin and run it from Tools > Regenerate Thumbnails, or use WP-CLI with the command wp media regenerate. Both methods go through your existing images and recreate every registered image size from the original files, so your media matches your current theme and settings.
WordPress creates resized copies of every image you upload, but those copies are based on the image sizes that existed at upload time. When you switch themes, change sizes in your settings, or add custom sizes in code, older images don't update on their own. This article explains what thumbnails are in WordPress, when you need to regenerate them, and how to do it safely with a plugin or the command line.
What Are Thumbnails in WordPress?
In WordPress, "thumbnails" usually refers to all the resized versions of an image that WordPress generates on upload, not just the small square thumbnail size. When you upload photo.jpg, WordPress may create files like:
photo-150x150.jpg(thumbnail)photo-300x200.jpg(medium)photo-768x512.jpg(medium_large)photo-1024x683.jpg(large)photo-1536x1024.jpgandphoto-2048x1365.jpg(extra large sizes used for responsive images)
Themes and plugins can register additional sizes, such as a featured image size for blog cards or a product image size for a store. WordPress stores information about each generated size in the attachment's metadata, which it uses to build the srcset attribute for responsive images.
The term also overlaps with "featured images," which WordPress internally calls post thumbnails. Regenerating thumbnails affects the image files used for featured images too.
When Should You Regenerate Thumbnails?
You don't need to regenerate thumbnails regularly. It's useful in specific situations:
-
You switched themes: Your new theme may register different image sizes, for example, a wider featured image. Older images won't have those sizes until you regenerate them.
-
You changed sizes in Settings > Media: Adjusting the thumbnail, medium, or large dimensions only affects new uploads.
-
You added a custom image size in code: Using
add_image_size()in your theme or plugin only creates that size for future uploads. -
You changed the crop setting: Toggling "Crop thumbnail to exact dimensions" for the thumbnail size requires regeneration to apply to existing images.
-
Thumbnails are missing or broken: If some image sizes failed to generate during upload, perhaps due to memory limits, regeneration can fill in the gaps.
-
You migrated your site and images look wrong: If metadata didn't transfer cleanly, regenerating can rebuild it.
-
You changed output format or quality: If you added filters to output WebP sub-sizes or adjust compression, regenerating applies the changes to existing images.
Before You Regenerate: Take a Backup
Regenerating thumbnails rewrites image files and metadata. It's usually safe, but it's a bulk operation that touches your entire media library. Before starting:
- Back up your
wp-content/uploadsfolder and database. Many hosts offer one-click backups, or you can use a backup plugin. - Check your disk space. New sizes add files, and a large library can grow significantly.
- Consider running it on staging first if your site is large or business-critical.
- Pick a quiet time. Regeneration can use significant CPU and memory, which may slow a busy site on shared hosting.
Method 1: Regenerate Thumbnails With a Plugin
The most popular option is Regenerate Thumbnails, a long-standing free plugin available in the WordPress plugin directory. It's the easiest route for most site owners.
Step-by-Step Instructions
-
Install the plugin: Go to Plugins > Add New Plugin, search for "Regenerate Thumbnails," then click Install Now and Activate.
-
Open the tool: Go to Tools > Regenerate Thumbnails.
-
Review the registered sizes: The page lists every image size currently registered on your site, along with their dimensions and crop settings. This is a handy way to see what your theme and plugins have added.
-
Choose your options:
- Skip regenerating existing correctly sized thumbnails: Speeds things up by only creating missing sizes.
- Delete thumbnail files for old unregistered sizes: Removes files for sizes that are no longer registered, freeing disk space. Be careful with this option if other plugins or hardcoded content rely on those old files.
- Update the content of posts to use the new sizes: Optionally updates image references in your posts.
-
Start regeneration: Click the button to regenerate thumbnails for all attachments, or only for featured images if that's all you need.
-
Keep the tab open: The plugin processes images one by one in your browser. Closing the tab stops the process, though you can restart it later.
-
Review the log: When it finishes, check for any images that failed, usually because the original file is missing or corrupted.
Regenerating a Single Image
You don't always need to process your whole library. With the plugin active:
- Go to Media > Library.
- Switch to the list view.
- Hover over an image and click Regenerate Thumbnails, or select multiple images and choose Regenerate Thumbnails from the Bulk actions dropdown.
This is useful when you only need to fix a handful of images or test your settings before running a full regeneration.
Method 2: Regenerate Thumbnails With WP-CLI
If you have SSH access to your server, WP-CLI is the fastest and most reliable method, especially for large libraries. It runs on the server, isn't limited by browser timeouts, and doesn't depend on keeping a tab open.
Basic Command
From your WordPress root directory, run:
wp media regenerate --yes
Without --yes, WP-CLI asks for confirmation before regenerating everything.
Only Generate Missing Sizes
To save time and server resources, only create sizes that don't already exist:
wp media regenerate --only-missing --yes
This is ideal after adding a new image size or switching themes, because existing sizes are left alone.
Regenerate a Specific Image Size
If you've added or changed one size, you can target just that size:
wp media regenerate --image_size=large --yes
Replace large with the name of your custom size, such as mytheme-card.
Regenerate Specific Images
Pass attachment IDs to limit regeneration to certain images:
wp media regenerate 123 456 789
Regenerate Only Featured Images
You can combine WP-CLI commands to regenerate only images used as featured images. First, collect the attachment IDs stored in the _thumbnail_id meta key with a quick SQL query, then pass them to the regenerate command:
IDS=$(wp db query "SELECT DISTINCT meta_value FROM $(wp db prefix)postmeta WHERE meta_key = '_thumbnail_id'" --skip-column-names)
wp media regenerate $IDS --yes
If you'd rather avoid the command line for this, the plugin's "featured images only" option does the same job.
Handling Large Libraries
For libraries with tens of thousands of images:
- Run commands inside
screenortmuxso they continue if your SSH connection drops. - Use
--only-missingwhere possible to reduce work. - Monitor server load, especially on shared or small VPS plans.
- Check for errors in the output and investigate any images that fail.
On multisite networks, add --url= to target a specific site, for example wp media regenerate --url=example.com/blog --yes.
How to Add a Custom Image Size (and Then Regenerate)
A common reason to regenerate is adding a new image size to your theme. Here's how you register one. Add this to your child theme's functions.php or a custom plugin:
/**
* Register custom image sizes.
*/
function sajjad_register_image_sizes() {
// Hard-cropped card image for blog listings.
add_image_size( 'sajjad-card', 600, 400, true );
// Soft-cropped wide image that keeps proportions.
add_image_size( 'sajjad-wide', 1600, 900, false );
}
add_action( 'after_setup_theme', 'sajjad_register_image_sizes' );
The fourth parameter controls cropping:
true: Hard crop to exact dimensions, centered by default.false: Scale proportionally so the image fits within the dimensions.- An array like
array( 'center', 'top' ): Hard crop with a specific focus position.
If you want your custom size to appear in the block editor's image size dropdown, add it with the image_size_names_choose filter:
/**
* Make custom sizes selectable in the editor.
*/
function sajjad_image_size_names( $sizes ) {
return array_merge(
$sizes,
array(
'sajjad-card' => __( 'Card', 'sajjad' ),
'sajjad-wide' => __( 'Wide', 'sajjad' ),
)
);
}
add_filter( 'image_size_names_choose', 'sajjad_image_size_names' );
After adding the code, regenerate thumbnails with wp media regenerate --only-missing --yes or the plugin to create the new sizes for existing images. You can then use them in templates:
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'sajjad-card' );
}
Cleaning Up Old Thumbnail Sizes
Over time, especially after several theme changes, your uploads folder can accumulate files for image sizes that are no longer registered. These files waste disk space and make backups larger.
Options for cleaning them up:
- Use the Regenerate Thumbnails plugin option to delete files for old unregistered sizes during regeneration.
- Remove sizes you don't need in code so they're no longer generated:
/**
* Stop generating sizes this site does not use.
*/
function sajjad_disable_unused_sizes( $sizes ) {
unset( $sizes['2048x2048'] );
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'sajjad_disable_unused_sizes' );
Be cautious when deleting old files. If a post's content references a specific old file such as photo-640x480.jpg, deleting it will break that image. Posts inserted through the block editor usually reference standard sizes and use srcset, but older content or page builder layouts may hardcode specific files.
Troubleshooting Regeneration Problems
The plugin stops partway through: Your server may be timing out or running out of memory. Increase the PHP memory limit, try again with "skip existing" enabled, or switch to WP-CLI.
"The originally uploaded image file cannot be found": The original image is missing from the server, perhaps due to a failed migration or cleanup. Restore it from a backup or re-upload the image.
Images still look the same after regeneration: Clear your page cache, CDN cache, and browser cache. Also confirm that your theme actually uses the size you changed.
Site slowed down during regeneration: This is normal on smaller servers. Run the process during low-traffic hours or use WP-CLI with --only-missing.
Offloaded media (S3, cloud storage): If your images are stored remotely through an offload plugin, regeneration may require the originals to be available locally. Check the offload plugin's documentation for its recommended approach.
Scaled images and originals: For large uploads, WordPress keeps the original and uses a -scaled version as the full size. Regeneration uses the original file where available, so sizes are generated from the highest-quality source.
FAQ: Regenerating Thumbnails in WordPress
No. WordPress only creates image sizes at the moment an image is uploaded. If you change themes, image sizes, or crop settings, you need to regenerate thumbnails for existing images.
It's generally safe, since WordPress recreates sizes from your original images. Still, it's a bulk operation, so take a backup of your uploads folder and database first, especially on large sites.
It depends on the number of images, the number of registered sizes, and your server's resources. Small libraries finish in minutes, while very large ones can take hours. WP-CLI with the only-missing option is usually fastest.
No. Original uploads are kept. Only the resized copies are recreated, and old unregistered sizes are removed only if you explicitly choose that option.
Often, yes. If your new theme registers different image sizes, such as a new featured image size, regenerating ensures older images have those sizes available.
Yes. With the Regenerate Thumbnails plugin, use the link in the Media Library list view, or run wp media regenerate followed by the attachment ID in WP-CLI.
Conclusion
Regenerating thumbnails in WordPress is a simple task once you know when it's needed. Whenever you switch themes, change image sizes, add custom sizes, or notice missing or distorted thumbnails, running the Regenerate Thumbnails plugin or the wp media regenerate command brings your entire media library in line with your current setup.
Take a backup, choose the method that suits your comfort level and library size, and use options like "only missing" to save time and server resources. With your thumbnails regenerated, your images will display at the right sizes, look sharp, and support responsive loading across your whole site.


