If you’ve recently changed your WordPress image sizes in Settings → Media or updated functions.php with new add_image_size() values, you might notice your existing images still appear in their old dimensions.
That’s because WordPress only generates new sizes for future uploads by default.
To fix this, you need to regenerate thumbnails — but many site owners don’t want to install yet another plugin just for a one-time task.
The good news? You can regenerate images in WordPress without a plugin by adding a simple PHP script to your theme’s functions.php file.
Why Regenerate Thumbnails?
Updating your image sizes improves:
- Website speed (smaller images load faster)
- Visual quality (larger sizes for HD and retina displays)
- SEO ranking (optimized images improve Core Web Vitals)
- Consistent design (cropped or scaled images match your theme layout)
The No-Plugin PHP Method
Here’s the safe way to regenerate all WordPress images directly in your functions.php.
Steps:
- 1. Backup your website before making changes.
- 2. Add this code to your functions.php file:
// TEMP: Regenerate all thumbnails without a plugin
add_action('init', function () {
if (!current_user_can('manage_options')) {
return; // Only admins can run this
}
$run_key = 'regen_done_2025_08_10'; // Change to run again
if (get_option($run_key)) {
return;
}
$attachments = get_posts(array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1,
'fields' => 'ids',
));
if ($attachments) {
require_once ABSPATH . 'wp-admin/includes/image.php';
foreach ($attachments as $attachment_id) {
wp_update_attachment_metadata(
$attachment_id,
wp_generate_attachment_metadata($attachment_id, get_attached_file($attachment_id))
);
}
}
update_option($run_key, 1);
echo '✅ WordPress thumbnails regenerated successfully. Remove this code from functions.php.';
exit;
});
- 3. Visit your website while logged in as admin — the code will run once and regenerate all images.
- 4. Remove the code after it finishes.
- After changing thumbnail, medium, or large sizes in WordPress
- When adding new custom image sizes with add_image_size()
- If you removed cropping and want proportional thumbnails
- When optimizing for retina displays or full-width images
Benefits of Regenerating Images Without Plugins
- No extra plugin load → faster site speed
- Total control over the process
- Works on any WordPress theme
- Perfect for developers and advanced users
Final Thoughts
While plugins like Regenerate Thumbnails are still a great option for beginners, advanced users can use this no-plugin method to regenerate WordPress images quickly and cleanly.
Just remember to remove the code after running it to keep your site optimized.