How to remove unused images in WordPress

Learn about various methods to remove unused images in WordPress and unused media in the media library.

Managing an extensive WordPress media library can be daunting, especially with multiple authors. Different naming patterns sneak in, variations of the same image, and no way to determine which data is still up to date. If you don’t remove unused images in WordPress, they will clutter your site, slow down performance, and waste valuable mental and storage space.

I’ve been there multiple times when running various websites, from small local NGOs to large portals with up to 40 milion monthly page impressions.

In this guide, I’ll share my approaches to tackling the media clutter and how I effectively remove unused images from WordPress sites and keep them running smoothly.

Why Remove Unused Images from WordPress?

Unused images can significantly impact your website’s performance. They take up unnecessary space, increase backup sizes, and can even slow down your site. Not to mention the time you need to find something. By removing these images, you can:

  • Improve website speed – and page speed scores
  • Reduce hosting costs
  • Save storage space
  • Increase backup times
  • Make everyone in the project a little bit happier

As I learned recently during a talk at WordCamp Leipzig, reducing the server load by removing unused images also contributes to a greener, more environmentally friendly web presence.

File sizes times X

When I started managing WordPress sites, I didn’t pay much attention to the media library. Over time, it became a mess of unoptimized, unused, and duplicate images. Cheap hosting packages reached their storage limit, and backups took forever. It wasn’t until I decided to tackle the issue that I realized the impact these unused images were having.

One thing not everyone is aware of is that each uploaded image is stored multiple times by WordPress. On upload, our beloved CMS creates the image in various sizes. While this is great when serving optimized images to devices matching them in the frontend, keeping all of them stored on the server needs two or three times the space of the original image file.

The number of unused images and the disk space it reserves showing in the WordPress dashboard.

How to Identify Unused Images in WordPress

I wrote a detailed post about how to find unused images in WordPress, especially if you want to get your hands dirty in the database.

Identifying unused images is the first step in removing them from your WordPress media library. There are two main methods: manual identification and using a plugin.

Manual Identification

You can manually find and remove unused images from the media library. If you are tech-savvy, see the post I linked above. Here are the quick steps for a non-techy way, though with lower reliability.

  1. Go to your WordPress dashboard and navigate to Media > Library.
  2. Use the Uploaded to column to get an idea of possible unused images. See Delete Unattached Media in WordPress for more details.
  3. You can also sort by the Date to look at older images first. Often, they are more likely to be outdated.
  4. Open each image, post, and page on your site to see which are possibly unused. You can also try searching for the image ID, image URL, or title in the post search in the backend to find usages.
  5. Click “Delete permanently” on the image edit page or use the bulk options in the list view of the media library to remove an unused image file from your server. Be aware that WordPress does not check if the image is still referenced anywhere.

I spent a lot of time doing these steps during my maintenance runs. And yes, it is as much fun as it reads.

Enter a much quicker and more reliable solution.

The WordPress plugin to remove unused images

Eventually, while developing my Image Source Control plugin to manage photo credits, I gathered enough experience with how WordPress stores and manages images to extend it into a WordPress plugin to remove unused images.

The plugin made the process much easier, allowing me to identify and remove unused media quickly. My server performance improved noticeably, backups became faster, and my maintenance work shortened significantly.

Features of Image Source Control

  • Automatic Scanning: The plugin scans your site for unused images, making the identification process quick and easy.
  • Detailed Reports: Provides detailed reports on image usage, helping you decide which images to keep or remove.
  • Easy Removal: Allows easy removal of unused images directly and in bulk.
Steps to remove unused images in a WordPress plugin.
Run a deep check before removing unused images in the media library.

Remove Unused Images with ISC

  1. Purchase and Install the Plugin: Go to Plugins > Add New > Upload. Install and activate the plugin.
  2. List Unused Images: Navigate to Media > Unused Images to see potentially unused images. Over time, Image Source Control scans your whole site in the background, and the list becomes shorter.
  3. Run the Deep Check: Run the Deep Check on multiple or individual images to check if they might still be used outside post content.
  4. Remove Unused Images: Select the images you want to remove and choose “Delete” in the bulk options above the table.

This method is not only quicker but also reduces the risk of accidentally deleting images that are still in use.

The pitfall: Unattached vs. Unused Images

Unattached images are those not linked to any post or page. These can often be mistaken for unused images but might still be necessary for specific purposes, such as background images or theme assets. It’s essential to distinguish between genuinely unused images and unattached ones still in use.

To identify unattached images:

  1. Navigate to Media > Library.
  2. See the Uploaded to column for unattached images.
  3. Manually check if these images are used in widgets, theme settings, or custom CSS.
The WordPress Media Library in List view with the links highlighted to attach or detach images from posts.
It is risky to remove unattached images using the Uploaded to column

Removing unattached images can free up space, but ensure they are not required for other site functionalities. See Delete Unattached Media in WordPress for more details on how the Uploaded to column actually works in WordPress core.

Good to know: Image Source Control does not only monitor post content, but also allows you to run a deep check in meta fields and options to find unattached images that are still in use outside of posts.

Make removing unused images less likely

I am doing a few things to reduce the chance of unused images.

With all the ease and reliability of using Image Source Control to remove unused images from your media library, I still make sure to have a backup set up in case something goes wrong. In my case, my host is taking care of this for me.

As mentioned above, I have maintenance lists for my WordPress sites. Using Image Source Control to remove unused images makes that task much less scary. It moves the item from “maybe now and then when I have the time, and this looks like a fun task” into a quarterly task that is mainly a link to the Unused Images page in the backend to take a quick look.

Now that I am even more aware of image sizes, I improve images before uploading. Some of my sites use plugins like the Modern Image Formats. I also like tinypng.com, a service that converts files into improved WebP versions.

I have also documented my standards for image uploads, including size and format guidelines. This ensures consistency and helps in managing the media library more efficiently. This documentation includes a manual checklist before publishing a post, which reminds me to check image sizes again.

I also ensure that guest authors know about my standards, but I like to double-check just in case.

Conclusion

Maintenance is not fun for me, but with the right tools, it doesn’t require much time or nerves. Once you complete the first review of image usage, you only have to do it once in a while.

As the developer of the Image Source Control plugin, I encourage you to try it out and see how it can help you remove unused images from your media library.

Portrait of Thomas Maier, founder and CEO of Image Source Control

Questions? Feedback? How can I help?

Reach out directly via the contact form.