WordPress Media Library Clean

What to use

Use the Media Cleaner Plugin (https://meowapps.com/plugin/media-cleaner/) by Jordy Meow. The plugin gets excellent reviews.

Note: if you use a Page Builder such as Beaver Builder, you should ensure it is supported by the plugin and will require the pro version. At the time of writing the pro version supports:

  • WooCommerce
  • ACF
  • BeaverBuilder
  • WPBakery
  • Elementor
  • Divi
  • Avada

How to use it

Under Analyse, set the plugin to check in all areas that the file is not in use (outside of pages) this should include:

  • Posts
  • Post Meta
  • Galleries
  • Widgets

Steps:

  1. Take a full site backup
  2. Download a complete copy of your /wp-content/uploads directory
  3. Ensure you are running the latest version of the plugin
  4. Set Media Cleaner settings to:
    • use Media Buffer: 50
    • Posts Buffer: 10
    • Analysis Buffer: 5
    • Delay: 200
    • (use 5, 1, 1, 50 for very slow hosts)
  5. Enable the media trash
  6. Run a Filesystem (Pro) scan, including:
    • Media
    • Posts
    • Post Meta
    • Widgets
    • Logs
  7. Check error log at https://www.yoursite.com/wp-admin/admin.php?page=meowapps-main-menu&tool=error_log

Finally, run another scan to check for links that are missing the files behind them using the Media Library method, with no additional options checked

Important Notes

Review manually, if media are unattached from the post or page, they may be reported as not in use incorrectly.

Media may be attached to a single post, but also be in use elsewhere.

Media may be showing as attached to a post, but no longer in use on a post.

Plugin Documentation

  1. https://meowapps.com/plugin/media-cleaner/
  2. https://meowapps.com/media-cleaner-tutorial/
  3. https://meowapps.com/media-cleaner-debug-issues/
  4. https://meowapps.com/media-cleaner-faq/
  5. https://wordpress.org/support/plugin/media-cleaner/

Total items in media library 2,184
Total Issues: 1,765

There are 1,765 issue(s) with your files, accounting for 120.94 MB

before doing anything, take a backup of your site (uploads and database)

when change replace/change images and other files in posts and pages, many people don’t bother to delete the old content. as a result your Media Library to becomes a mess which slows down your site and make media management very difficult.

this leads to hugely bloating media libraries (/wp-content/uploads) which over time affects memory, storage and system performance.

Media Cleaner scans the media library AND can scan the uploads folder directly. The pro feature will check if your upload folder contains files which are not in use on your site.

the plugin will add all files not being used on your website (such as in posts, pages, or galleries) to a temporary trash bin. You can then look over the files to be sure you want to delete them, and make their removal permanent.

WordPress can create a lot of thumbnails that aren’t used or needed
Remember that if you don’t need all those image sizes, you can use the remove_image_size function of WordPress or plugin such as Stop Generating Image Sizes.
https://codex.wordpress.org/Function_Reference/remove_image_size

the trash is contained in the database, and when the plugin is removed, the tables created by Media Cleaner might have been removed (normally not when the plugin is simply disabled though).

Slider Revolution and NextGen galleries?
wpmc-trash folder

Pro version will find unregistered thumbnail sizes

https://meowapps.com/media-cleaner-tutorial/#Delete_All_Thumbnails all the files created for a certain base image will be deleted (but not the main image).

use Regenerate Thumbnails to re-create the thumbnails that you need while updating the Media with those thumbnails.

https://imagekit.io

Filesystem (Pro) scan finds images that are uploaded in your uploads directory and their filenames are not somewhere inside your database.
First use method “Media Library” and then “Filesystem (Pro)”.

The plugin adds 3 tables in your database:

– wpmcleaner
– mclean_scan
– mclean_refs
the wpmc_uninstall function delete those tables when the plugin is disabled (through the WordPress’ register_deactivation_hook).

turn off caching if possible

multisite compatible? Yes, but you will need to run it on every site independently. n be installed, just not “network activated” Normally the /sites directory is totally skipped by the process

files which are registered in the metadata
orphan files (which Media Cleaner Pro can detect

it will not delete a random size if the main file is there, for the simple reason that it might be used (custom crop).

detects Featured Images as used

With the latest update, you can actually get all those generated thumbnails and delete them. Then use Regenerate Thumbnails. It’s part of my tutorial, the 4th section: https://meowapps.com/media-cleaner/tutorial/. Keep in mind that only the Pro version of my plugin analyzes the raw Filesystem. The Free version works only with the Media and their metadata.

thumbnails left over from old images sizes that don’t match any of the currently registered sizes, but are just sitting there in your uploads directory taking up space.

If you want to force Media Cleaner to skip directories, you can add it/them to the Directory Regex Filter, and set it like this:

/^((?!sites).)*$/

That will avoid all the content of /sites to be scanned. You can add more:

/^((?!sites|network_sites|protected_images).)*$/

Drafts and Scheduled Posts are considered as active posts 🙂 They are included in the scan.

Normally, on uninstall, the plugin removes the tables it has created in the database. If not, please look for the tables mclean_scan and mclean_refs. You can remove them safely.

“ignore” is not technically a folder, it is simply a tag on the items Media Cleaner detected.

if I press this button will only the trash folder be permanently deleted or will the “ignored” folder also be permamently deleted?

The ignored… will be ignored

If a Media entry reference a file that doesn’t exist, then it’s marked as a broken Media

It’s working with widgets, I am resolving the shortcodes, and analyzing the URLs, so it should actually work

Reset DB button
the Reset button will actually not delete the files in the Trash, it will only delete the references to them in the internal DB of Media Cleaner

Have a look at your Uploads directory (using FTP for example), and you will see a directory called “wpmc-trash”. You will need to delete this one

Usually pictures in the media library are used in posts, however admin may use pictures in custom theme banners, sliders (revolution slider, essential grid, etc).

https://trello.com/b/8U9SdiMy/meow-apps-features

Here is a command which will delete all generated thumbnails
Navigate to your uploads directory, and run this command:
find . -name x*.jpg | xargs rm -f