Prevent WordPress from Generating Image Sizes
In this article
WordPress automatically creates multiple copies of every image you upload, each sized for different layout contexts (thumbnail, medium, large, plus any theme or plugin-specific sizes). Over time, these extra files can bloat your server storage and slow down backups. This guide shows you how to stop WordPress from generating those additional image sizes, either by disabling them entirely or by limiting them to only the sizes you actually use.
What You'll Need
- Access to your WordPress admin dashboard (to use a plugin or theme functions file).
- FTP or cPanel File Manager access if you choose to edit your theme's functions.php file (recommended).
- A backup of your site (always a good idea before making code changes).
Step-by-Step
Option 1: Disable All Image Sizes (Except the Original)
This method completely stops WordPress from creating any thumbnail, medium, or large versions. Only the original uploaded file remains.
- Connect to your site via FTP or open cPanel File Manager.
- Navigate to
wp-content/themes/and open your active theme's folder. - Find the
functions.phpfile and download it to your computer for editing (or edit directly in the file manager). - Add the following code at the end of the file, before the closing
?>tag (if present):add_filter( 'intermediate_image_sizes', '__return_empty_array' );
- Save the file and upload it back to the server, overwriting the original.
- Test by uploading a new image. You should see only the original file in your Media Library.
Option 2: Disable Specific Image Sizes
If you want to keep some sizes (like a featured image) but remove others, you can filter which sizes are generated.
- Follow steps 1-3 from Option 1.
- Add this code, modifying the array to list only the sizes you want to keep:
add_filter( 'intermediate_image_sizes', 'my_custom_image_sizes' ); function my_custom_image_sizes( $sizes ) { // Keep only 'thumbnail' and 'large' return array( 'thumbnail', 'large' ); } - Save and upload the file.
Option 3: Use a Plugin (Easier for Beginners)
- In your WordPress admin, go to Plugins > Add New.
- Search for "image size control" or "disable image sizes".
- Install and activate a reputable plugin (e.g., "Image Sizes" or "Simple Image Sizes").
- Go to the plugin's settings page (often under Settings or Media).
- Uncheck the image sizes you want to disable, or choose to disable all.
- Save changes.
Common Mistakes
- Not clearing existing image sizes: The code only affects new uploads. Existing images already have multiple sizes stored. You'll need to regenerate thumbnails (using a plugin like Regenerate Thumbnails) to remove old sizes.
- Disabling sizes your theme needs: Some themes rely on specific image sizes for layout. Disabling them can break the design. Always check your theme documentation.
- Editing the wrong theme: If you use a child theme, edit the child theme's functions.php, not the parent theme's (your changes will be lost on parent theme updates).
- Forgetting to re-enable when needed: If you later add a plugin that requires a specific size, you'll need to adjust the filter.
Tips
- Before disabling all sizes, consider if you use images in widgets, sliders, or social share previews. Those often need specific dimensions.
- Keep the original image as large as possible. You can still manually crop or scale images in the Media Library when needed.
- If you only need to reduce storage, consider compressing images instead of disabling sizes. A plugin like Smush can help.
- Test on a staging site first if possible, to avoid breaking your live site.
- After making changes, check your site's front page and a few posts to ensure images still look correct.
Troubleshooting
Images still being generated after adding the code: Clear any caching plugin (like W3 Total Cache or WP Super Cache) and your browser cache. Also, if you have a plugin that generates its own sizes (like WooCommerce), it may override the filter. Check the plugin's settings.
Site looks broken after disabling sizes: Re-enable the sizes by reverting your code change or plugin settings. Then, identify which size is needed by inspecting the broken image URL (it will contain the size name).
Code not working at all: Make sure you've added the code correctly and that there are no PHP syntax errors. Check your site's error log. If you're not comfortable with code, use the plugin method instead.
Existing images still have multiple sizes: Use a plugin like Regenerate Thumbnails to delete unused sizes. Be cautious: this will delete all generated sizes for existing images, so ensure your theme doesn't need them.
Frequently Asked Questions
Will this affect images already uploaded?
No, the code only applies to new uploads. Existing images retain their generated sizes until you delete them manually or use a regeneration plugin.
Can I disable image sizes for specific post types only?
Yes, you can conditionally apply the filter. For example, you could check if the current post type is 'post' and only then disable sizes. However, this requires more advanced coding.
What happens if a plugin needs a specific image size that I've disabled?
WordPress will try to use the closest available size, but the plugin may not display correctly. It's best to keep sizes that are essential for your active plugins.
Does disabling image sizes improve site performance?
It can reduce storage and backup size, but it may not significantly improve page speed. In fact, if you disable a size that the theme uses, the browser will load a larger image, which could slow things down.
Is it safe to delete all generated image sizes?
Only if you're sure no theme or plugin needs them. Test thoroughly after deleting. If something breaks, you can re-enable sizes and regenerate.
Can I set custom image sizes instead of disabling them?
Yes, you can use add_image_size() to define your own sizes. This is often better than using the default sizes, as you can tailor them to your exact layout.