When you are changing themes on a site or altering the image sizes used on a WordPress site, you’ll have to regenerate all the image sizes. Maybe you ran into the situation that you want to move the site and will have to generate new images again, after the move. For those that have SSH access to their site or local development environment, here are two simple tips I used for as long as I can remember them 😁.
Find & delete generated images
By default WordPress stores the generated image files in the following format:
// WordPress generated image file names
<your-image-file-name>-SIZExSIZE.jpg
// Example for a thumbnail image size
my-wonderful-image-of-a-cat-150x150.jpg
The files generated will be stored in the uploads folder, usually within the wp-content folder on your site. On Linux based server or macOS, you usually have access to the find command:
The aforementioned commands will find and delete the generated image sizes for you, but be careful, it’s a very powerful command.
Regenerate WordPress image sizes
The second gist regenerates all the image sizes. Make sure you have the WordPress command line interface installed on your server. Otherwise you can use a plugin like Regenerate Thumbnails.
I’d be careful there – it’d delete any file with an x in the middle of the file name! Try this: find -E . -type f -regex “.*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)”
Thank you Mark, you are totally right about the danger with my version. Updated the gist with your code.
if your OS doesn’t accept -E
find . -type f -regextype posix-extended -regex “.*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)”
Thanks Bernhard for your enhancement.