I want to delete all the resized images while leaving the original image. I have more than 20 GB of unused data taking up room on the server. For example:

  • first-image-name.jpg
  • first-image-name-72x72.jpg
  • first-image-name-150x150.jpg
  • first-image-name-250x250.jpg
  • first-image-name-300x300.jpg
  • first-image-name-400x400.jpg
  • first-image-name-1024x1024.jpg
  • second-image-name.jpg
  • second-image-name-72x72.jpg
  • second-image-name-150x150.jpg
  • second-image-name-250x250.jpg
  • second-image-name-300x300.jpg
  • second-image-name-400x400.jpg
  • second-image-name-1024x1024.jpg

Is there a way to delete all the resized images and disable creating such ones in the future?

  • 3
    You can probably clear the extra sizes by clearing out global $_wp_additional_image_sizes; and removing calls to add_image_size() - as for deleting existing files maybe use wordpress.org/plugins/regenerate-thumbnails
    – jgraup
    Sep 28, 2016 at 0:37
  • 1
    That plugin doesn't delete redundant files in my experience. @jgraup Sep 28, 2016 at 7:48
  • @AndyMacaulay-Brook, May be this can do
    – bravokeyl
    Oct 7, 2016 at 3:21
  • regenerate thumbnails DOES in fact delete un-used crops if your theme doesn't have that size registered. at least as of 2021.
    – NickFMC
    Jul 12, 2021 at 22:42

12 Answers 12


A majority of the answers covered how to stop creating future default image sizes but this doesnt account for creating any custom sizes in your theme but here is another solution to add to functions.php:

function wpse_240765_unset_images( $sizes ){
    unset( $sizes[ 'thumbnail' ]);
    unset( $sizes[ 'medium' ]);
    unset( $sizes[ 'medium_large' ] );
    unset( $sizes[ 'large' ]);
    unset( $sizes[ 'full' ] );
    return $sizes;
add_filter( 'intermediate_image_sizes_advanced', 'wpse_240765_unset_images' );

and you can also turn off future default image generation by setting the images to zero:

enter image description here

but to remove the images other then the originals I've ran into your same issue when I forgot to set it to not do it and what I did was:

  • Download all the photos locally using an SFTP service, I love Transmit (paid) but you can use something like Filezilla (free) .

  • Download all the files to a directory.

I'm on a Mac but any terminal that allows bash will work. I coded a simple bash script:

# !/bin/bash

for imageWithSize in $(find "$DIRECTORY" -type f -regex '.*/[a-z-]*-[0-9].*.txt$'); do
    echo rm $imageWithSize

The folder is located on my desktop, and for the question I named it question240765. I used .txt files to test this but you can change it to .jpg. I saved it as a bash file image_dust.sh so that it will allow me to modify or enhance later down the road. Run the script first with the echo and you could even dump it to a file with changing the line:

echo rm $imageWithSize 


echo rm $imageWithSize >> result.txt

which will log everything to the file result.txt and allow you to browse it before really removing them. If all is well change that line to:

rm $imageWithSize

If you're curious here is what the regex does:

  • [a-z-]* looks for filenames like foo-bar or fo-fo-bar. if you have uppercase letters in your name use [A-Za-z-]*
  • -[0-9] after the filename it looks for the remaining - (dash) with a number [0-9]
  • .*.txt looks for anything after the first digit to the end of the name with the extension.

After completing the scripting and running it. You could blow everything away on your site and re-upload the images. If you're worried about file size I would even use imagemagick but I prefer sips to reduce the compression size of the images.


You can easily delete files using "find" command on linux, just needed to do the same thing. You can run the following in bash console:

cd /var/www/wordpress/wp-content/uploads
find -type f -regex '.*[0-9]+x[0-9]+.\(jpg\|png\|jpeg\)$' -delete

No idea, how to remove existing images. But you can stop generating image sizes for new images you are going to upload.

If you like to write codes: Place this code snippet in your theme's functions.php file-

add_filter( 'intermediate_image_sizes_advanced', 'wpse_240765_image_sizes' );

function wpse_240765_image_sizes( $sizes ){
    $sizes = array();
    return $sizes;

Or with a plugin: Use this plugin- https://wordpress.org/plugins/image-sizes/

It'll give you the same output. You can even choose which of the image sizes you want to be prevented from creating. enter image description here


If coding is not your strongest point you may want to look at a plugin solution.

What I have in mind is a suggestion of a couple free plugins residing in the WordPress repository:

I must admit that I have not yet used the first one - Media Cleaner - so I cannot provide you with a solid opinion.

I have used though the second one - Optimize Images Resizing - and had the expected results.

Points to always look for in any case:

Before attempting anything,

  • I cannot stretch enough the importance of creating a full backup of your WordPress installation (both your uploads folder and your dB).
    I do understand that we are talking about 20GB but a backup is essential, especially in this unique situation.

  • This procedure is time consuming as well as heavy on the server.
    It is wise to put your site in the maintenance mode.

  • Delete orphan attachments

After all is done use your favorite Regenerate Thumbnails plugins to get your WordPress/themes image sizes back as well as install EWWW Image Optimizer and Imsanity. This combination will guarantee optimized, resized, only necessary images.

Plugin specific points.

Media Cleaner

  • "Files detected as un-used are added to a specific dashboard where you can choose to trash them. They will be then moved to a trash internal to the plugin. After more testing, you can trash them definitely".
  • Some plugins may clash with it. If that happens and assuming you are on maintenance mode, deactivate all and do your cleaning.

Optimize Images Resizing

  • "TO REMOVE image sizes generated prior to activating the plugin, visit the Settings -> Media and use the button under "Remove image sizes" to perform the cleanup".
  • Read this support thread: Urgent questions on processing existing images

Thumbnail Cleaner

  • Includes functions like: Creating backups of your uploads, analyzes your uploads directory, giving you an overview how many original files and thumbnails there are, restores backups in case you have lost a file that was not supposed to be deleted.
  • Read this support thread: Backup only original image

Please let us know how you achieved the best results.

  • Note - Only Media cleaner has had any update in the last 3 years.
    – Stender
    Dec 2, 2019 at 9:11

If you have SSH access then you can run the following commands to list and remove the resized images. Later you can rebuild them.

List all resized images.

# List all resized images.
# Usage: lrimg site.ext
function lrimg() {
  cd ~
  cd /var/www/"$1"/htdocs/wp-content/uploads/
  find . -regextype posix-extended -regex ".*-[[:digit:]]{1,9}x[[:digit:]]{1,9}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f
  cd $THE_PWD

Remove all resized images.

# Remove all resized images.
# Usage: lrimgrm site.ext
function lrimgrm() {
  cd ~
  cd /var/www/"$1"/htdocs/wp-content/uploads/
  find . -regextype posix-extended -regex ".*-[[:digit:]]{1,9}x[[:digit:]]{1,9}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f -exec rm {}  \;
  cd $THE_PWD

Be careful here. Keep your backups ready.

P.S. My server has an NGINX setup which is why the site paths are /var/www/"$1"/htdocs/ $1 being the parameter which is the site name. You can modify it to match your path.

  • A little improvement for your regex: ".*-[[:digit:]]{1,9}x[[:digit:]]{1,9}(@2x)?\.((jpg|jpeg|png|eps|gif))" This modification ensures that only the last occurrence of a dimension-like pattern is matched. By doing so, it effectively ignores earlier dimension-like sequences that might be part of the image's descriptive name rather than its size. This is particularly useful for accurately identifying and processing image files in environments where filenames include multiple dimension-like patterns, ensuring that operations such as image resizing or deletion target the correct files.
    – emjay
    Apr 9 at 6:54

To remove all superfluous image files, we'll have to loop through all posts, find the attachments to those posts, establish which attached image sizes are no longer needed and remove those files. Here we go.

First, get all (custom) posts and pages and loop through them:

$the_query = new WP_Query (array ('posts_per_page' => -1, 'post_type' => 'any'));
foreach ($all_posts as $post) { ... }

Next for $post get all the attached images and get a list of all media sizes. Then loop through them:

$images = get_attached_media ('image',$post); // returns array of post objects
$sizes = get_intermediate_image_sizes(); // returns array of identifying strings
foreach ($images as $image) {
  foreach ($sizes as $size) {

Now for this image and size, find the url and delete the file

$att = wp_get_attachment_image_src ($image->ID,$size); returns array of file properties
wp_delete_file ($att['url']);

I'd give this code a thorough test before applying it... With 20GB in images it could also take a while to execute.


Here's a way you can do this programmatically (for the most part).

1: Set your media sizes (ex: thumbnail 300x300 and the rest 0x0 to keep WP from generating anything other than thumbnail.)

2: Generate the new images with WP CLI, but do not delete any of the old sizes until it's ready. Or if you really are not keeping any resized images, skip this.

$ wp media regenerate --skip-delete

3: Search replace image paths with WP CLI. This updates posts and pages content so you don't have broken images on your site.

Your regular expression will need to be something like the following.


Regular expression visualization

Debuggex Demo

And would have the following wp search-replace:

$ wp search-replace '(\/wp-content\/uploads\/)([0-9]{4}\/[0-9]{2}\/)(.*)(-[0-9]{1,5}x[0-9]{1,5})(\..{2,4})' '$1$2$3$5' --regex

Or you might have a different upload folder or don't have the year/month folders included. In that case you'd have slightly different regex


Regular expression visualization

Debuggex Demo

and you'd run

$ wp search-replace '(\/app\/uploads\/)(.*)(-[0-9]{1,5}x[0-9]{1,5})(\..{2,4})' '$1$2$4' --regex

Just to be clear: this would make your load times horrible - all images would serve from their full-size file and not the smaller image. It would be a good idea perhaps to swap your image server with an image processing API / CDN so these problems go away :)

If you are at least keeping one thumbnail, like the 300x300 example I gave, you'd need to run a little different regex:


Regular expression visualization

Debuggex Demo

Then you run WP CLI twice. The first swaps all the images that aren't the 72x72 thumbnail. The latter changes all the 72x72 thumbnails to the new 300x300 thumbnail

$ wp search-replace '(\/wp-content\/uploads\/)(.*)(-(?!(?:72))[0-9]{1,5}x(?!(?:72))[0-9]{1,5})(\..{2,4})' '$1$2$4' --regex

$ wp search-replace '(\/wp-content\/uploads\/)(.*)(-72x72)(\..{2,4})' '$1$2-300x300$4' --regex

4: now delete all unused images:

$ wp media regenerate

1) To stop WordPress from creating multiple image sizes upon uploading of an image, you can accomplish this without using a plugin.

Navigate to Settings > Media in the admin section.

By setting the sizes to 0 you will disable WordPress from creating default image sizes and only the original image will be stored.

enter image description here

2) To reduce the 20GBs of images you have on your site, I would simply SFTP into your server and manually delete the different sized images. From the root directory of a WordPress install, navigate to wp-content/uploads/<yyyy>/<mm>/ and you will find all of your images and media uploads. You want to be sure to leave the original image, or else you are simply deleting the entire image. Any image file name with an extra - ###x###.jpg is an auto generated image. The original image would not have this in the file name.

As an aside - to help you with your images I would check out WPMU DEV's WP-Smush plugin.

WP-Smush - Image Optimization

It's really great and when you upload images it automatically uses their servers to crunch and compress images before storing. It also can size down large resolution images to a reasonable maximum size. You really shouldn't have to display an image that is bigger than 2048x2048.

  • Ok ... how to SFTP and delete additional resized images ??? Sep 28, 2016 at 19:21
  • This is the program I use to SFTP into my server. winscp.net/eng/download.php It basically lets me browse the contents of the entire wordpress install, and I can edit any file in my text editor; I can easily add and remove files with this as well. It will depend on your hosting provider to get setup and logged in with SFTP. Sep 28, 2016 at 20:34
  • Or Cyberduck, which has an OSX and Windows version. cyberduck.io/?l=en Sep 28, 2016 at 20:45
  • Can it done using FTP Client ? Sep 28, 2016 at 20:45
  • That's basically the same thing. The S simply standing for Secure FTP. Sep 28, 2016 at 21:06

The flowing steps should do it:

1)You should start by removing any unneeded image sizes from your relevant files e.g. functions. PHP in your theme and any plugins if the exist (e.g. rudderless).

2)Next you can delete all required image sizes via ftp.

3)Then you need to regenerate the thumbnails (e.g. all the image sizes that Wordpress is being told to create.) You can use any 'Regenerate thumbnails' plugin from the WP repo.

Alternatively try this: 1) Same as step 1 above

2) There are a couple of plugins in the plugin directory(repo) which will delete all WP thumbs and then only generate the thumbs when they are called for the first time on any given page on your website. On subsequent request for the image, the image will already exist and be served as normal. The benefit of this is that thumbs are only created for images/sizes that are actually required by your site. However, images called in non-standard ways may not get generated.

If you want to reduce additional overhead from excessively large original images you can use 'imsanity' plugin to reduce the physical file size of these originals down to a size of your choice. It's a great tool for sites with user submitted images.


I ended up using filezilla to connect via ftp. I then searched the uploads folder using the remote file search feature within Filezilla. I used regex in combinations to select all and delete. i.e. \d\d\dx\d\d\d.jpg or \d\dx\d\d.png or \d\d\dx\d\d\d\d.gif. I kept using different combinations of the "\d" to find either a 3 digit by 4 digit size of image or a 2 digit by 2 digit size of image.


I am no coder but this works - found it at this url https://crunchify.com/wordpress-tips-how-to-remove-redundant-image-sizes-and-files/

ssh into your public_html

Use the following (without the quotes) to find all the images of that nominated size "find . -name -72x72."

This line removes images of the nominated size "find . -name -72x72. | xargs rm -f"

then just change the 72x72 to the next image size

Removes a thousand images in one second - you will think it didn't work until you check your uploads and see they are gone.

  • In general it's safer to use -exec with find than xargs since it avoid issues with whitespace or other characters in filenames that need to be escaped.
    – Rup
    Mar 15, 2021 at 14:59

I too faced the same problem and finally found the solution. It worked 100% for me. I have cleared nearly 10GB of files.

The command lines below will remove currently resized images, including Retina versions so that we can correctly resize WordPress images per the new theme dimensions. And yes, we're using the command line, because I (Michael) am old school.

cd /home/example/public_html/wp-content/uploads

find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f -exec rm {} \;

Reference - https://www.axelerant.com/blog/remove-resize-wordpress-images

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.