[Smush Pro] Check for unused images.

2

It would be great to have some mechanism to detect unused images.

1) I would imagine that it would create a table in the database that would check when an image was last used on the site.
2) Then run a check that runs through the sitemap to run all the pages in turn and find the URLs and image names used.
3) Some sort of summary listing is created, showing unused images that could be individually or collectively deleted.

  • Amin Nazemi
    • Staff

    Hi Kuczys

    Trust you are doing great.

    We already have a couple of similar requests for adding a feature to allow automatic cleanup of the media library from images that are not used, and I agree that could be a very helpful feature.

    However creating such a feature would not be easy, as not all images that are added to the media library can be found on the database and even if they are added there running a search may not be able to find them all, also some images might be hardcoded in files, so if remove the wrong images in the result your site may end up being broken.

    Our Smush team is still looking to find a good way to add this feature. but, I can’t give you any ETA.

    Best Regards,
    Amin

    • Kuczys
      • Code Norris

      Yes, this is a problem and so far all plugins that would solve this are failing.

      Is there any way to add a record to images that will save the date and time of the last retrieval?

      1) If it’s an image on the site (front-end), it would be enough to run a sitemap that would crawl all the pages and when loaded, it would find out which image is loaded.

      2) If it’s going to be in the admin and the image is linked to a plugin, it probably wouldn’t matter because the missing image will load with the next update.

      3) It would probably be enough to be able to choose that the images are from the WP-CONTENT/UPLOAD/[years] directory

      Then list the images and for which one wouldn’t be sure, cross them out. Anyway, it’s great that you’re doing this and I believe you’ll figure something out.

      Good luck

  • Jair Jaramillo
    • Staff

    Hello Kuczys

    WordPress doesn’t have a default way to determine when an image in the Media library has been used on posts or pages, nor to identify when was the last time it was used. And while the Sitemap is capable to record the images in the posts, that won’t necessarily be a record of all the images that your site is currently using.

    While we mentioned that we are considering the possibility to implement your feature request on Smush, as a workaround, there is already a plugin that has that purpose:
    https://wordpress.org/plugins/media-cleaner/

    According to its documentation:
    https://meowapps.com/media-cleaner/tutorial/

    The plugin looks and compares the images in the Media Library in order to see if they appear in The Content of your site, and tells you which ones would be safe to delete. Being a 3rd party plugin, our support scope is limited, and I suggest you to make a backup of your site before using this tool.

    Kind regards,
    Jair.