I'm working on a site which has a media library that is now 7GB - and I really want to clear out all the unused images.

I've tried using the Media Cleaner Plugin: https://wordpress.org/plugins/media-cleaner/ But this seems to clear out images that I am using - this seems to be because my whole site is built with Advanced Custom Fields.

Does anyone have any suggestions on how I could delete images that aren't being used?


1 Answer 1


I think you have already discovered the problem with a plugin approach. They will look for unlinked media (images not associated with a post) and remove those files. As you have said, you are using custom fields and you may also have uploaded images inside your post content.

Sadly the only option I can think of is to use a find command to get a list of all of your wp-content/uploads and then reduce that list by removing all images in use. As a starting point, you could try the WP-CLI database search command.

You'd want to allow for the different generated image sizes given that a thumbnail or medium image may be used, but you'd want to keep the original + all scaled variants.

It goes without saying that you should have a full backup of your database and files before running anything like this!

I'd be interested if someone can provide a more elegant and robust solution, but this is probably how I'd approach the problem.

  • Thanks Alexander! I'll have a think about doing something like that. Wish there was a more elegant solution.
    – M.T
    Commented Apr 25, 2019 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.