How i can remove unused images in wordpress?

1.3k Views Asked by At

i am importing csv to import products using wp all import plugin. Sometimes import failed and all of the images of the products imported because products are not impotred properly and images remains in media i want to remove unattatched or unused images from media of wordpress library.How can i do that?

I WANT TO DELETE ALL UNATTATCHED IMAGES AT ONCE I tried using media unattatced files but images are more than 50 thousand i want to remove them all at one click

4

There are 4 best solutions below

1
Richard On

There is no fast way, perhaps a plugin, but I cannot guarante 100% results.

According to wordpress, you can delete images marked as "Unattached", this is done the following way:

Go to Dashboard -> Media

Next, click on the drop-down menu where it says "All Media Items" you can select "Not Attached".

However, you can not rely on this system 100% due to the following:

  1. Images edited through the media library’s image editor will frequently become unattached, and show up as unattached, even if they are already in use.
  2. Uploading images through Media -> Add New always show as unattached even when they are subsequently inserted into a post.
  3. Images inserted into a post, which are then also inserted elsewhere, will show as unattached if the original post is deleted even though the image still occurs in another post.

The fastest way to remove ALL IMAGES is through FTP access or file management through your hosting provider dashboard.

In there you will locate your uploads folder which looks something like: /wp-content/uploads/2023/06

You will locate all image files under each subfolder (in this case subfolder /06), along with multiple regenerated image files.

You have to remember that image links will be broken if you use the images on your website. There is no way to recover this change, unless you do proper backup.

0
Mera On

The mentioned solutions above all address what you are looking for. It is either doing it thru custom code, manual, or plugin.

The solution using FTP is on point however fraught with risk.

I came across your problem as well and found this plugin. It is mix between the custom code and FTP to delete unused images in one shot.

I spoke to the owner about the plugin because the setup I had over 90000 images and wanted to know if you could handle it.

They said it should be no problem. They use the same code for their own clients and have tested it to over 100k images on small VPS instance with one cpu. However they did say, in shared hosting environments the process will be slower. For example, they used it on one of their clients who hosted with GD with 40k images and it took about 4 hours for the software to scan and identify all the unused images and media. After that they used a one shot delete to remove them all. Not as fast as FTP, but close.

Plugin- https://mediahygiene.com/

0
Deepak Lakhara On

You should give a try to Media Hygiene WordPress Plugin to delete unwanted images in WordPress.

It will help to find unattached images, and allow whitelist, blacklist, one shot download for safety, one shot delete as well.

Free version - https://wordpress.org/plugins/media-hygiene/

Pro version https://mediahygiene.com

0
HS LOH On

WordPress automatically saves one image in multiple sizes, resulting in inefficient use of storage space. While plugins can address this issue, many are paid and difficult to use. If you back up regularly, you can efficiently manage storage space with this program/code.

Simple PHP program : http://hyunsik.me/wordpress/?p=23140