Manage your WordPress wp-content folder

My other blog has around 900 posts with 1,700 images in my WordPress Media Library. But my wp-content folder has over 20,000 images!

That folder looks like this:

The wp-content folder is a mess

What is happening here!?

What’s happening of course, is that WordPress tries to do a little bit too much thinking for you. And it creates lots of image resolutions and sizes — called thumbnails — when you upload an image. In my case up to 8 extra images were created on each image upload.

Note: Your WordPress Media Library will only show you one image, but under the hood there are (in my case) up to 8 images. You can only see them on your file system.

Thumbnails

I love WordPress, but I don’t need WordPress to do that, because I don’t want a million files idling on my server.

They take up space and are (in my case) mostly useless.

Because the images I upload are usually already small and compressed and my posts have maybe one or two images. And my readers have fast connections, so speed is not really a big deal.

Of course YMMV, but for my theme and use-case; I don’t need extra thumbnails.

Here’s how I handle the images in my wp-content folder and how I got rid of all the unnecessary ones with these plugins.

Disable thumbnails generation

I use the Disable Generate Thumbnails plugin. Because it’s the most straightforward.

Very simple configuration

I have also used ThumbPress as an alternative.

Some of these sizes are theme dependent some are based on the media settings and others are hardcoded into WordPress.

You can also add a bit of PHP code that does this for you. But I chose a plugin.

Both plugins will stop WordPress from creating all these specific thumbnail sizes.

Imsanity

https://wordpress.org/plugins/imsanity

Install Imsanity and select a max resolution. This means whatever image you upload, it will be scaled down to this max.

  • You can choose to keep the originals or not.
  • And you can choose to do a bulk resize.
  • And automatically convert PNG to JPG. Great.
Imsanity

Imsanity is available per image from the Media List view. And you can resize per image.

You can use Imsanity with wp-cli to resize in bulk!

wp imsanity resize

Note: it seems that using the wp-cli will not inform the media list i.e. the GUI of the resize. So in your media-list it will still show the old size (and have an option to scale it down, which has already been done)>

WP-Optimize

https://wordpress.org/plugins/wp-optimize

WP-Optimize will compress your images even further. This is handy when you already have uploaded lots of images.

WP-Optimize

Summary

So with these three plugins:

  • Disable Generate Thumbnails: No new thumbs are created
  • Imsanity: Uploaded images are automatically scaled down
  • WP-Optimize: Compress existing and new images even further

And now the big reveal. How to get rid of all these already created thumbnails!

Force Regenerate Thumbnails

https://wordpress.org/plugins/force-regenerate-thumbnails

Install Force Regenerate Thumbnails. This awesome plugin will regenerate new thumbs and DELETE existing thumbs based on your current settings (i.e. none if you have set ‘Disable Generate Thumbnails’).

I.e. in my case it will create zero new thumbs and cleanly delete all the old ones!

You run it by selecting one or more media files from your Media Library and choosing the the Bulk action.

Here you can see that it regenerated the thumbs for one image by deleting two existing sizes and creating none.

Awesome!

You can also see in the database that this plugin does a clean rewrite of the image metadata. This is absolutely necessary because if this doesn’t happen some themes will look for thumbs that are gone and you will end up with a blogpost with ‘missing’ images!

Before
After

You can also do this with WP-CLI:

wp media regenerate

Handy if you want to run bulk actions.

I would really love it if these three things were incorporated in one plugin or maybe even WordPress core (media regenerate more or less is). But I am happy this works and can keep control of my wp-content folder.

Bonus: Media File Sizes

It does what it says on the box. You can sort your Media Library based on size (this really should be a WordPress core feature).

https://wordpress.org/plugins/media-file-sizes

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *