Tutorial: Cleaning WordPress with Media Cleaner

Media Cleaner is a very advanced tool and should be used by someone who understands WordPress well. Then it will deliver amazing results. First, remember to backup your install (database and /uploads directory) before using this plugin. If you don’t know how to, I recommend you the UpdraftPlus plugin. You can also do this on your staging website if you use WPEngine for example.

1. Introduction & Media Library Method

The basic/recommend options for a first scan are those. I recommend you to consider Posts, Post Meta, and Widgets as a set. There could have been only one checkbox called Content instead of those three.

Media Cleaner

Start the scan, then wait. It takes time depending on your install. If it stops suddenly, please check how to debug Media Cleaner. When it is finished, have a look at the results and firstly, search for the images used by your theme directly (usually, the header, the hero, the logo). Those might have been detected by the plugin but it is not certain, as it is often used silently by your theme. Mark them as ignored if they are part of the results.

Check the files which were detected as not in use. Are they really not in use? Check a few of them randomly, at least. Then delete them with the plugin. They will be moved to the plugin’s trash and the database entry for the media will be also kept.

Use your website for a while. Everything works? Empty the trash. Many broken files? Restore them using the Media Cleaner dashboard, or your backup.

2. Meticulous check with the Filesystem Method

I recommend doing this after having checked your Media Library first. Now that your Media Library is clean, we would like to know which files in your /uploads directory are actually not registered as part of a media. I would preferably use the following settings.

Media Cleaner Settings

All the files which are not part of a media will be detected. This makes sure that everything in your files is actually properly registered in your Media Library.

The combination of those two checks will make your install very optimized, sparkling. Everything is used and properly registered. Of course, this is ideal 🙂

Alternative: Check for Broken Media

Maybe you don’t really want, need or can perform a meticulous check of your install, and what you need is simply to detect the broken medias (which doesn’t have any files behind them). This scan will exactly require those settings.

Media Cleaner Settings

Logically, doing this would actually detect all your media as not used by your system, since they are not checked against anything. But the Media Cleaner will recognize those settings and will display a message in your dashboard to let you know that it will only scan for broken media.

The Settings

  • Media. Only for the Filesystem method. This will check if the files are registered in a media, including all the sizes.
  • Posts. This is important as it checks the content of your posts. The URLs, the CSS classes using the IDs of the media, the background images, the src-set even, and more. I have one website on which I use my images in posts only (this one: Offbeat Japan). I set the Method on Media Library and the only option I check is Posts. I use my Featured Image in my posts directly as well, but if I was not using it, I would also need to check Post Meta, as the Featured Image is stored in it.
  • Post Meta. This is where the Featured Image is stored, but not only! Many Page Builders are also keeping their data there, sometimes galleries, and so on.
  • Widgets. This is simply the widgets you have added. They sometimes contain images or even galleries.
  • Logs. This will create a file (reset for every scan) containing all the files detected in your install in a first section, then the result of the scan for every media/file in a second section. Very useful to debug the plugin.
  • queeckee

    Hi Jordy. that would me a nice option to have. something like a stop button, to pause the scan and allow user to worh with part results. in many posts / images sceneriu the scan would take too much time, is there any temporary result list to load or something after timeout?. i am asking in advance, scan is still running 🙂

    • queeckee

      WOW! i didnt except this. seems like wery well made.. i had accidentaly missclcked to leave te scan page, and result list is fantastic. even while in the half of scan. it found old diferent thiumbnail sizes as well. so i can only suggest this plugin for everyone! (dont forget to backup, and read notes twice, dont forget to activate media trash before you are happy to process delete! :))

  • 8 (ATE)

    I think our site is too large. It only gets to 9% and then it detects an error and just stops. The scan found 13,000 images. We were hoping this would work so we could purchase the PRO because we have thousands of images that need to be removed from our upload files (we’ve switched hosts 3 times in 2 years). I checked the error logs and don’t see anything as to why this is happening.

    • It seems very large indeed 🙂 But I want to make the Media Cleaner works on big installs as well, which is why the plugin improved a lot recently to support this, even if it has to analyze those kind of installs slower. Best is to check the error in the Developer Tools of Google Chrome but if you don’t know how to do it exactly, can you contact me through the Contact / Support page and I will try to make it work 🙂

  • Abdulrahman Nahhas

    I would ask to you also delete unused thumbnails? or just main images?

    I have a site since 2011 and we have a lot of articles. we change many themes and now I ned to clean the upload folder. when we delete the articles we dont delete the images. so I need to clean my upload folder I have a backup file with 10 GB. I dont know which images used or not. we have 20000 article.

    • We can’t delete the main images and keep the thumbnails, that would be a big mess 🙂 However, it’s true I could add an option to delete the thumbnails, as right now the plugin is safe and keeps the main image + thumbnails in case any of those images is in use.

      However, if you switch between themes and re-generate the thumbnails, indeed you would have thumbnails with are not even part of your database anymore and therefore, pure garbage. The Pro version of Media Cleaner detects those in the Filesystem mode and you can delete them, did you try?

  • pbourhis

    My CPU Usage is 100% when running the scan and of course your plugin stop. I would like to know the right settings I will have to use on my poor shared server? Because it seems that the settings you show us here in your screenshot are high?

    • Hi, that’s a bit strange but if your server is slow and you have a big database then it can happen easily yes. Give it a bit of delay, like 2000ms, and with a lower Analysis Buffer, like 1 😉 Does it work better?

  • Sarah

    When I try to empty trash or delete an image, it says Analyzing and nothing ever happens. Anything I can do to fix this?

    • Actually there is an issue and it’s showing Analyzing while actually it’s Deleting. But it should happen anyway. Did you check your PHP Error Logs?

  • RobRab2000

    Hi, Thanks for a great plugin. Before I upgraded to pro, the plugin found 3700 files in my media library. After I installed the pro version it is finding over 180,000!! So I’m very happy indeed that I purchased the pro version (very reasonable price too).

    The issue I’m having though is that with so many files, I’m finding it very difficult to get through them all in one go. Is there any way to run this from the command line on the server so that wordpress isn’t getting in the way?

    Alternatively is there a way to get it to automatically retry when it gets an error. I find that every half hour or so it has a 504 error and stops. I can get it going again by hitting retry without refreshing the page. This makes it really difficult to leave it running over night. If it would auto retry then it should be fine.

    Thanks again 🙂

    • RobRab2000

      oh dear, actually I have just realised that after getting to around 40% analysing and me deleting images along the way (around 42,000 images) it seems to have broken a lot of the the images on the site! I suspect it might be because I am using the cornerstone page builder and maybe it can’t see images in this?

      Is there anything I can do about this?

      • RobRab2000

        Hey, it turns out that the missing images were an issue with my DNS.. lol

        I will try the cleaner again 🙂

        • Ah yes, it’s important to make sure all caches are reset every time (including CDN). So maybe that’s why 😉 Happens often.

  • The Crystal Focus

    Hi Jordy,
    I’m back again and using the media cleaner pro because I inadvertently had retina create 11 versions of every image so I’m trying to prune my media library from 110,000 down to a more reasonable 1400 or so as it should be.
    I ran into issues with trying to move my site from localhost via MAMP (moved it local so that I could run WP/LR faster because I’m hashing almost 83,000 images in Lightroom Total Synchronization). The uploads folder had ballooned to over 18GB! In figuring out how to use media cleaner pro, I discovered the “wplr-tmp” folder – are those the hashes that Total Synch is creating? Because although I thought it was the retina creating all those versions that was causing my uploads folder to balloon to 18GB, it is actually that wplr-tmp folder that is now 17.4GB of that massive uploads folder! Do I need to keep all those temp files while WP/LR Total Sync is matching photos? Will Lightroom maintain its connections if those don’t go up to the server? Basically the problem seems to be that the restore is just timing out due to the size of that temp folder. Any suggestions?

    • Hi! The “wplr-tmp” is totally useless, it is temporary used to upload the photos, once they are uploaded and moved to WordPress Media Library they are removed from there. I am not sure why it happened, or maybe the Total Synchronization made this mess? It is actually a possibility and I will have a look. Meanwhile, you can delete this directory without thinking 🙂

      • The Crystal Focus

        Thank you! This 17GB albatross has been waddling its way to and from the server for no reason. Hope you enjoyed the ride, “wplr-tmp”, cause you’re gonna take a final ride to the trash now. 😉

  • nycmac.com

    Hi Jordy, images used by Slider Revolution and SiteOrigin Page Builder are marked as unused and deleted. It might be good to post a list of common plugins with known incompatibilities until they can be fixed.

    • Hello 🙂 There are way too many plugins to do that, so I try to maintain rather a list of plugins with which I am compatible. Please contact me directly (https://meowapps.com/contact/) as I keep a list of the most used plugins by my user to make them compatible 🙂

      • nycmac.com

        Thanks and you’re correct — I should have rephrased the suggestion to be about known *compatible* plugins.

  • Alice Erickson

    Hi Jordy, I just bought the pro version, and I’m trying it out on one of my own sites first. I uploaded and installed the plugin. First time around, I saw a Meow item on the nav bar, but clicking that gave me a “you can’t go there” type of message. I looked at the plugin, and it wasn’t showing as activated. I activated it – or tried to – and WordPress said it was activated. It wasn’t. It still shows the activate link. The Meow item is gone from the nav bar. I tried uninstalling and reinstalling. It still won’t activate. WordPress 4.9.1. Are there any known conflicts with other plugins? Any advice and help?

    • Alice Erickson

      Answered my own question. I needed to deactivate Wordfence. I did that, activated Media Cleaner and reactivated Wordfence. Seems fine now.

I recommend you to use WPEngine or SiteGround. They are both excellent hosting services and work perfectly with all my plugins.