I have a wordpress site running woocommerce. My site is extremely active. I literally sell items daily by the dozens and I am constantly adding new ones in. I understand I have to add the new ones manually, of course. But I wish there was a way that I could delete the images programmatically from the ones that I sold s that they don't clutter up the uploads folder. I have 33,235 images currently in there and 1290 products live.

Can this be done via functions.php file?
or htaccess file?
or perhaps a plugin you know about?

Thanks in advance

  • Depending on the theme and plugins running, on your website, the number of images files depends on the different image size create via add_image_size. If you remove some size (change theme for example), old image size couldn't be detect and delete as the size isn't recognize at this moment. You need to delete old size with ftp. Do you think it's your case ? – Benoti Oct 21 '16 at 12:29
  • I am already preventing the additional duplication of images that Wordpress does out of the box for thumbnails. What I am hoping to do is something that when a product item is no longer in stock or removed from my list of products, that it also deletes the image related to it from the database or upload folder. So that it doesn't appear in the media section, clutter the upload folder, or add size to the database for images I no longer need, – LOTUSMS Oct 21 '16 at 14:19
  • When you delete your product manually, it is suppose to do it. If not that because the image size is no longer registered as an image size. To do it programatically your script must retrievethe all attachement for the product, eventually scan a part of the file name to delete all it's attachement. Did you change your theme recently ? – Benoti Oct 21 '16 at 14:28
  • No problem, try to loop all folders and delete file that are not attachment of your active product, just a one time script in functions.php. – Benoti Oct 21 '16 at 21:24
  • Yeah. That is something I could use but I don't know the script. That's what I was hoping to get from someone here – LOTUSMS Oct 22 '16 at 12:07

If you want to remove the images from folder, There is a two way to remove image 1) Remove by manually 2) Remove by using plugin.

1) Using Plugin I suggest you that can try the Image Cleanup plugin and it's the best, but still good to make a backup first. There is an another one plugin available to delete un used images DNUI.

DNUI plugin will search image from the database and delete all unused images making space in your server and clean up the database from all them.

2) Manually You can also search through your Media Library for images which are unattached to posts and pages to delete them manually.

enter image description hereSimply go to Media > Library and click the Unattached link which will display all images that may be displayed on other parts of your site or simply not used.

It’s advisable to take a backup of your uploads folder & database before deleting any images stored in these directories and data in your db.

| improve this answer | |
  • Good stuff!!! I will test this out and come back to this. Thanks a bunch! – LOTUSMS Oct 27 '16 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.