How to Regenerate Thumbnails Without a Plugin in WordPress – 2026

Last updated on August 9th, 2024 at 11:12 am

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.

  1. Open your child theme’s functions.php file.
  2. 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.

  1. Add the following code to your functions.php file 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

  1. Log in to your WordPress admin dashboard.
  2. Navigate to Regenerate Thumbnails in the admin menu.
  3. Click the Regenerate Thumbnails button to start the regeneration process.
See also  How to Add Custom User Roles in WooCommerce - 2026

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.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top
0
Would love your thoughts, please comment.x
()
x
×