Unused Images

How it works

WordPress stores images in two parts:

  • The image files are stored on the server, typically in the ‘wp-content/uploads’ directory of the site.
  • A record of the image is then stored in the database, in the Media Library. This record also includes other data related to the image, such as the image tile, description or alt-text.

Images in the Media Library are also stored in different sizes, with a separate image file on the server for each size (typically thumbnail/small/medium/large). This can cause the uploads folder to become bloated with unused image files.

When populating the list of unused images, WP-Optimize will check both these locations for images

WP-Optimize will then scan the database for each of the detected images. This includes checking any posts, pages and custom post types (such as FAQs or eCommerce products) for featured or embedded images. Any image that can’t be matched to a record in the database will then be added to the list of unused images.

Please note that certain themes or page-builders may access images in a non-standard manner, in which case the images may be flagged as unused incorrectly. We recommend double checking before deletion if you are unsure, and keep an up-to-date backup of the site.

When removing an image, both the image files and Media Library record will be deleted.

Removing Unused Images

Open the ‘Images’ tab in the WP-Optimize admin page. You should see a number of images under ‘Unused images’. These are image files, found both in the Media Library and the ‘wp-content/uploads’ directory that are not attached or embedded in any posts or pages.

Highlight 'Unused Image' tab

Note: WP-Optimize will cache this list, so will not update the list every time (to prevent unnecessary queries to the database). To make sure the list is fully up-to-date, press the ‘refresh’ button in the top right of the tab.

Highlight 'refresh button'

Select the images to remove using the check-boxes (There is also the option to select all or none), and then press ‘Remove selected images’. WP-Optimise will then delete all copies of the selected image file plus any record in the Media Library.

highlight 'Remove Unused Images' button

Removing Images by size

Please note that removing registered image sizes is for experienced users, and care should be taken that the image size in question is not used on the site.

WP-Optimize also has the option to remove image files by size. This tool shows both all registered image sizes, and image sizes that are currently not in use.

highlight 'Registered Image Sizes' section

The ‘Registered image sizes’ section shows a list of all image sizes that are present on the site. This includes sizes for images that in use. Deleting a registered image size will remove all images of that size from the uploads folder, including any that are in use.

In this case, the Media Library record will only be deleted if all copies of an image have been removed.

The ‘Unused image sizes’ section shows any image sizes that are currently not used by any images on the site.

Select any image size (from either section) that you wish to remove, and press ‘Remove selected sizes’.

We recommend taking a backup of the site before performing any optimisation with WP-Optimize. WP-Optimize integrates with our backup plugin, UpdraftPlus. If UpdraftPlus is active on the site, the option to take an automatic backup before images are removed will be displayed in the tab.

Posted in: General Usage