If you want to delete all auto-generated image sizes while keeping original images using WP-CLI, follow these steps:


1️⃣ Find Auto-Generated Image Sizes

Run this to list all registered image sizes in your setup:

shCopyEditwp media image-size list

You’ll see output like:

yamlCopyEdit+------------------+-------+------+
| name            | width | height |
+------------------+-------+------+
| thumbnail       | 150   | 150  |
| medium          | 300   | 300  |
| large           | 1024  | 1024 |
| medium_large    | 768   | 0    |
| 1536x1536       | 1536  | 1536 |
| 2048x2048       | 2048  | 2048 |
+------------------+-------+------+

These are the sizes that WordPress auto-generates. You can disable them in functions.php, as mentioned before.


2️⃣ Delete Auto-Generated Image Files

This command will delete all images except the original uploads:

shCopyEditwp media regenerate --skip-delete

By default, wp media regenerate deletes old sizes and regenerates new ones. Since you’ve disabled image generation, running it with --skip-delete ensures that it only removes thumbnails without regenerating them.

If you want to remove all generated images, including those from themes/plugins, use:

shCopyEditwp media regenerate --only-missing

3️⃣ Remove Orphaned Image Metadata

After deleting thumbnails, some unused metadata may still exist. Clean it up with:

shCopyEditwp db query "DELETE FROM wp_postmeta WHERE meta_key LIKE '_wp_attachment_%';"

And remove orphaned attachment posts (for deleted images):

shCopyEditwp db query "DELETE FROM wp_posts WHERE post_type = 'attachment' AND NOT EXISTS (SELECT 1 FROM wp_postmeta WHERE wp_postmeta.post_id = wp_posts.ID);"

4️⃣ Prevent Future Images From Being Auto-Generated

Since you don’t want WordPress to create extra images at all, you should set all image sizes to zero:

shCopyEditwp option update thumbnail_size_w 0
wp option update thumbnail_size_h 0
wp option update medium_size_w 0
wp option update medium_size_h 0
wp option update large_size_w 0
wp option update large_size_h 0
wp option update medium_large_size_w 0
wp option update medium_large_size_h 0
wp option update large_size_w 0
wp option update large_size_h 0

And disable scaled images:

shCopyEditwp option update big_image_size_threshold 99999

5️⃣ Prevent Monthly Upload Folders

Stop WordPress from creating year/month subfolders:

shCopyEditwp option update uploads_use_yearmonth_folders 0

Final Check

  1. Upload a new image via the WordPress dashboard.
  2. SSH into your server and navigate to /wp-content/uploads/.
  3. Only the original image should exist—no extra thumbnails.

Now, WordPress won’t generate new images, and all old ones are removed! 🎯 Let me know if you need adjustments! 🚀