Regenerating thumbnails in WordPress is essential when you add new image sizes or change existing ones. While plugins can handle this task, you might prefer a code-based solution to keep your site lightweight. This guide will show you how to regenerate thumbnails in WordPress without using a plugin.
Why Regenerate Thumbnails?
When you upload an image to WordPress, it generates several thumbnail sizes based on your settings. If you later change these settings or add new sizes, the existing images won’t automatically regenerate. Regenerating thumbnails ensures that all images are available in the new sizes, maintaining the visual integrity of your site.
Step 1: Add the Regeneration Function to Your Theme
You’ll need to add a custom function to your theme’s functions.php file. If you don’t have a child theme, you can use our free child theme generator.
- Open your child theme’s
functions.phpfile. - Add the following code to create a function that regenerates thumbnails:
/*
* Snippet: How to Regenerate Thumbnails Without a Plugin in WordPress – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1363
* Tested with WooCommerce 10.7.0
* "Function to regenerate thumbnails"
*/
function wcsuccess_regenerate_thumbnails() {
// Get all attachments
$attachments = get_posts(array(
'post_type' => 'attachment',
'numberposts' => -1,
));
// Process each attachment
foreach ($attachments as $attachment) {
$image_path = get_attached_file($attachment->ID);
// Check if the file exists
if (file_exists($image_path)) {
// Regenerate thumbnails
wp_update_attachment_metadata($attachment->ID, wp_generate_attachment_metadata($attachment->ID, $image_path));
}
}
}
Step 2: Execute the Regeneration Function
To execute the regeneration function, you can create a custom admin page or run the function using a direct call. For simplicity, we’ll demonstrate how to create a custom admin page.
- Add the following code to your
functions.phpfile to create a custom admin page:
/*
* Snippet: How to Regenerate Thumbnails Without a Plugin in WordPress – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1363
* Tested with WooCommerce 10.7.0
* "Create custom admin page for thumbnail regeneration"
*/
function wcsuccess_register_custom_admin_page() {
add_menu_page('Regenerate Thumbnails', 'Regenerate Thumbnails', 'manage_options', 'wcsuccess-regenerate-thumbnails', 'wcsuccess_regenerate_thumbnails_page');
}
add_action('admin_menu', 'wcsuccess_register_custom_admin_page');
function wcsuccess_regenerate_thumbnails_page() {
if (isset($_POST['wcsuccess_regenerate'])) {
wcsuccess_regenerate_thumbnails();
echo '<div class="updated"><p>Thumbnails regenerated successfully!</p></div>';
}
?>
<div class="wrap">
<h1>Regenerate Thumbnails</h1>
<form method="post">
<input type="hidden" name="wcsuccess_regenerate" value="1" />
<p>
<input type="submit" class="button-primary" value="Regenerate Thumbnails" />
</p>
</form>
</div>
<?php
}
Step 3: Access and Use the Admin Page
- Log in to your WordPress admin dashboard.
- Navigate to
Regenerate Thumbnailsin the admin menu. - Click the
Regenerate Thumbnailsbutton to start the regeneration process.
Conclusion
By following these steps, you can regenerate thumbnails in WordPress without relying on a plugin. This approach is ideal for those who prefer a lightweight solution or want to keep their site plugin-free. Remember to always back up your site before making significant changes to your files or database.
For more customization tips and tools, don’t forget to check out our free WordPress child theme generator.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

