3 Ways To Easily Clean Up Your WordPress Site By Deleting Unused Images

delete unused wordpress images

Deleting unused images is an important part of maintaining a WordPress site. Unused images can slow down page speed, increase storage costs, and make it difficult to keep track of content. Fortunately, there are several methods that can be used to efficiently and quickly clean up any WordPress site by removing these unused images.

There are multiple options for cleaning out the media library and optimizing the image sizes within it. This can be done either manually or by using plugins such as Media Hygiene and Media Cleaner, which simplify and automate the process. Furthermore, code can also be written for more specific demands.

With all these methods available, it is possible to quickly remove any unnecessary media files or optimize existing ones on any WordPress site with minimal effort. 

Let’s take a look at these methods.

Removing Unused Images Methods

The most efficient way to eliminate redundant images from a WordPress site is through the use of plugins or custom code.

The media library of WordPress contains all the files, including images, which have been uploaded to the website. Deleting unused images stored in the media library can free up disk space and improve quality on the server. Furthermore, removing such content from the dashboard also helps provide more organized navigation for users.

Plugins are an effective tool for cleaning up any WordPress site as they enable one to quickly delete unused images with a few clicks. Additionally, some plugins also provide advanced features such as automatically deleting orphaned files, safely moving them to trash before deletion so that they can be easily restored if needed, and scanning for duplicates across multiple locations on a WordPress site.

Custom code is another option for those who wish to manually remove redundant data from their website’s media library. This requires careful coding along with knowledge of how WordPress works and image optimization techniques in order to ensure that only unnecessary items are deleted while keeping valuable content intact on the server.

By implementing either plugins or custom coding solutions, users can easily clean up their WordPress sites by deleting unused images without impacting other crucial aspects such as web performance or user experience.

Using Plugins to Delete Unused Images in WordPress

Comparing the efficiency of plugins to custom coding solutions, users can effectively eliminate unnecessary items from their website’s media library while preserving valuable content. Plugins provide a convenient and reliable way for WordPress users to delete unused images with minimal effort. Popular plugins include Media Hygiene, Media Cleaner, and WP-Optimize which are designed to quickly scan through settings, databases, and other areas of the website.

It is important to note that using these plugins or other plugins that have the same functionality will not always guarantee complete removal of all unwanted images – some may remain in the upload folder even after deletion process is complete. Therefore, it is recommended that users take extra precautions when deleting or disabling any image files from their WordPress website as this could potentially cause problems on your site if done incorrectly or without proper backups in place.

Let’s take a look closer Media Hygiene and Media Cleaner

Media Hygiene

The Media Hygiene plugin for WordPress is designed to help users optimize their WordPress media library by removing unused media. This process helps free up server space, reduce clutter, and improve server performance. The plugin offers features such as bulk delete and deep folder scanning, making it a useful tool for finding and deleting unused images and media.


  • Compatible with major WordPress builders (e.g. Divi, Enfold, Elementor, etc.)
  • Informative dashboard showing list of all file types and space used
  • Whitelist files for safekeeping
  • Delete and download by page (10 items at a time)
  • Deep folder scanning (Pro) 
  • Works with WooCommerce (Pro)
  • Works premium plugins like custom fields, sliders, SEO plugins (Pro)
  • Bulk delete and download all images (Pro)

Media Cleaner

The Media Cleaner plugin for WordPress is a tool designed to clean up the WordPress media library. It achieves this by deleting unused media entries and files, as well as fixing broken entries. The plugin includes an internal trash feature, allowing users to preview and confirm changes before permanently deleting anything.


  • Cleans and remove all media types
  • Supports various themes (Pro)
  • Support Woocommerce (Pro)
  • Filesystem Analysis (Pro)

Manual Cleanup of Unused Images

Manually sorting through a website’s media library and eliminating unnecessary image files can be an effective way to keep a WordPress site organized. It is important to first make sure that all page, post, product, and user content is backed up before attempting any manual clean up of images. After backup is complete users should review different menus such as the themes menu, plugins menu, comments menu and widgets menu for any additional images that may need to be kept.

Once you have made a note of important images not to be deleted or removed, follow these steps to remove unused images in the WordPress Media Library.

  1. Backup your site: Before making any changes, it’s crucial to backup your site to prevent any accidental data loss.
  2. Access your Media Library: From your WordPress dashboard, go to “Media” > “Library”.
  3. Check for Unused Images: Look through your media files and identify any images that aren’t being used on your site. You can check this by seeing if the image is attached to any posts or pages.
  4. Delete Unused Images: Once you’ve identified unused images, you can delete them. Click on the image, then click “Delete Permanently”.
  5. Bulk Delete: If you have multiple images to delete, you can use the bulk delete option. Select the images you want to delete, then from the “Bulk Actions” dropdown, select “Delete Permanently” and click “Apply”.

Removing Unused Images using Code

Using code to remove unused images from a WordPress site can be an intricate task, requiring precision and skill to successfully execute without negatively impacting the site’s functionality.

There are several ways in which one can use code to delete these images. WordPress performance expert Sabrina Zeidan explains using some php code, you can also remove unused images from the WordPress media library.

Removing unused image attachments

When you remove your posts, the attachments associated with them aren’t automatically deleted. They remain in the WordPress Media Library and on your web server, consuming disk space and potentially causing clutter.

The function provided below will permanently delete these attachments. This includes removal from both the Media Library and the wp-content/uploads folder on your server.


Delete all attachments related to a specific custom post type

This function comes in handy when you need to eliminate all images linked to a specific Custom Post Type (CPT). For instance, if you previously had a CPT that you’ve since deleted or migrated, leaving it behind.

Remember to replace “card” with the name of your specific custom post type.

Executing this function will result in the deletion of both the attachment from WordPress and the actual file from your web server.


Delete all attachments whose files are no longer present on a web server and give a 404 error (blank thumbnails in Media Library)

Does your Media Library contain images that aren’t showing up? When you try to access them, do you receive a 404 error page stating that the image no longer exists?

This is a symptom of a broken link problem. The file associated with that attachment no longer exists on the web server, leaving behind empty placeholders in your Media Library, like ghosts of images that once were.

You can use this function to remove these images from your WordPress Media Library. It will tidy up your Media Library by eliminating all WordPress attachments linked to files that are no longer available on the web server.

Please note: this function can be resource-intensive!


Using code to clean up unused WordPress images is fairly efficient. The downside is that you need to understand the code and the logic before moving forward with these techniques. Failure to understand the code and its effects can mean deleting images permanently.

Preventative Measures to Keep WordPress Media Library Clean

Preventive methods of avoiding unnecessary image uploads can be implemented to reduce server load times and ensure efficient data storage. Here are some tips:

  1. Delete the images you don’t want immediately after posting. 
  2. When uploading images, know what you are uploading. Use small batch sizes.
  3. Periodically review your Media Library to make sure images are attached to a post. If not, see where these images are being used.
  4. Reduce the file size by adjusting the resolution before uploading the image
  5. Use image compression tools to reduce the size of the file


The task of deleting unused images from a WordPress site can be a time consuming and tedious process. However, it is an essential step for keeping your website running smoothly and securely.

Statistics show that more than half of all websites contain at least one plugin that has not been updated in over two years, which is a significant security risk. To protect your site from being vulnerable to malicious attacks, it is important to take the necessary steps to delete any unused images.

By using plugins and tools available or manually cleaning up the images yourself, you can quickly and efficiently clean up your WordPress site.

Frequently Asked Questions

What types of images should I delete?

In order to effectively clean up a WordPress site by deleting unused images, it is important to understand which types of images should be targeted.

An effective way to identify these images is to look for ones that have not been used recently or have not been linked in any posts or pages.

Additionally, all images that are outdated, irrelevant, or simply no longer needed should be removed from the website.

Utilizing this method can drastically reduce the size and clutter of your WordPress site while also making it more efficient and organized.

Should I delete images from my Media Library?

The use of images in WordPress sites is an important part of creating a visually appealing and functional website. However, if these images are not being used, they can take up space that could be better used for other content or resources.

It is therefore important to consider whether or not to delete any unused images from the media library. This requires assessing the benefits of keeping them compared to the potential cost savings in terms of storage and speed by deleting them.

In most cases, it is best to delete any unused images from the media library in order to optimize the performance of a WordPress site.

How often should I delete unused images?

Unused images can take up valuable space on a WordPress site, so it is important to regularly delete them.

It is recommended that users delete any unused images from their WordPress media library at least once per month.

Automated solutions such as plugins or writing code can help streamline the process of deleting unused images, making it easier and more efficient for users to maintain their WordPress sites.

What is the best way to delete unused images?

Deleting unused images is an important task for maintaining a WordPress website. It helps to reduce clutter and improve the user experience.

There are several ways of removing unused images, such as manually deleting them, using plugins or writing code.

Manual deletion is the simplest method but can be time consuming; plugins provide a more automated approach but may not be suitable for all users; whereas writing custom code offers greater flexibility but requires technical skills.

Ultimately, the best way to delete unused images will depend on the individual’s skillset and preferences.