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, you can use WP-Optimize Premium to 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 and press the “Unused images and sizes” tab.
To scan your website for unused images, press the “Scan website for unused images” button. WP-Optimize will now scan for unused 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.
You will now be presented with all the unused images that are on your site. To delete these images, either individually select the images by clicking on the images to highlight them, or press the “Select all” button to delete all unused images.
Once you have selected all the unused images you want to delete from your site, scroll down and either choose “Move selected images to trash” or “Delete the selection permanently”. WP-Optimise will then delete all copies of the selected image file plus any record in the Media Library.
You will receive a notification that your images have now been deleted.
Removing Images by size
You can also choose to remove unused images by size, but 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.
This tool shows both all registered image sizes, and image sizes that are currently not in use.
The ‘Unused image sizes’ section shows a list of all image sizes that are present on the site. This includes sizes for images that are 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’.
Restoring images that were moved to trash
If you are not sure if you might still need the image, you can send it to trash, instead of deleting it permanently. You can view and restore these images by pressing the “view trash” button.
Here you can restore any trashed images you want to keep by highlighting them and pressing the “Restore the selection” button. These images will now be sent back to your image library.
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