-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Issue: "On our WordPress site we need to identify unused images and delete them because our hosting storage plan is at its max."
Chat GPT response:
Step 1: Backup Your Site
Before deleting anything, create a full backup of your site, including the database and wp-content/uploads folder, in case something goes wrong.
Step 2: Identify Unused Images
Option 1: Use a Plugin
-
Install a Plugin
Use a plugin like [Media Cleaner](https://wordpress.org/plugins/media-cleaner/) or [Advanced Database Cleaner](https://wordpress.org/plugins/advanced-database-cleaner/).- Media Cleaner scans your media library and identifies unused images.
- It cross-references images with posts, pages, and custom post types to detect files that are not in use.
-
Run a Scan
- Go to the plugin settings.
- Perform a scan to identify unused media files.
-
Review the List
- Carefully review the list of unused images before deleting them.
Option 2: Use WP-CLI (Advanced)
If you are comfortable using WP-CLI, you can list unattached media files:
wp media list --status=unattachedThis will show images that are not attached to any post or page.
Option 3: Manual Review (Time-Consuming)
- Go to Media > Library in the WordPress admin.
- Switch to the "List" view and sort by the Uploaded To column.
- Look for files with "Not attached" and manually verify if they're still in use.
Step 3: Delete Unused Images
Using Plugins:
- After identifying unused files, plugins like Media Cleaner allow you to delete them in bulk.
Using File Manager or FTP:
- Access the Server
Use cPanel's File Manager or an FTP client like FileZilla. - Navigate to
wp-content/uploads/
Review old image folders for unused or orphaned files. - Delete with Caution
Cross-check files before deleting to ensure they’re not hardcoded in themes or custom post types.
Step 4: Optimize Remaining Images
- Use a plugin like [Smush](https://wordpress.org/plugins/wp-smushit/) or [ShortPixel](https://wordpress.org/plugins/shortpixel-image-optimiser/) to compress images.
- Remove unnecessary image sizes generated by WordPress using the
remove_image_sizefunction in your theme'sfunctions.php.
Step 5: Prevent Future Clutter
-
Figure out what image sizes are not used in our theme
First we need to find what image sizes are used for each page in our theme code. Image sizes in WordPress -
Disable Unnecessary Image Sizes:
Add this to yourfunctions.phpfile to prevent WordPress from generating certain image sizes:add_filter('intermediate_image_sizes_advanced', function($sizes) { unset($sizes['medium']); unset($sizes['large']); unset($sizes['thumbnail']); return $sizes; });
-
Use a Media Library Organization Plugin:
Plugins like [Media Library Organizer](https://wordpress.org/plugins/media-library-organizer/) can help keep your media library clean going forward.
Final Recommendations:
- Start with plugins to avoid manual effort.
- Review the list of unused images carefully to avoid accidentally deleting important files.
- Once unused images are deleted, monitor your storage regularly to prevent future issues.