Delete not used image wordpress DNUI

This post is old, i have to remake it

This plugin help you to identify all image not used in your wordpress post and page, and give you the option to delete them, this will delete the image from the server and update the database so that the image is no longer shown when making a post, because the problem of wordpress is, if you upload one image, wordpress can make 4 image from the same file, so this plugin help you to identify all them and delete the image what you want.


  • Upload the zip file from the plugin interface of wordpress
  • Or upload the the folder from the unzipped to the folder of wp-content\plugins

How work

This plugin make a scan of your data base and find all the files you never used in a post, this only will show you 25 files for each time, but are going to see 25 files parents(the original image) and maybe for every parent 4 sons(the image made aaaxbbb)

dnui 1

The search code uses the rule that the post should be referred to the desired image, so if nicearma.jpg image is not on any post this picture is taken as not used, so the plugin will allow you to delete the image, otherwise it will not let youdelete the image, since the box will be disabled.

Note: If your wordpress site does not use this rule you might see pictures with the option to erase, therefore follows the recommendation 2

Note:For the moment you only can choose the sons if this image was not used in older post (i’m working on the option of delete the fathers to)

After selecting the image and sent to the Delete button will appear a message thatwill tell if the image could be deleted or not

dnui 3

And if you check the field  should not exist anymore, so the image on the server (you may see another time, but give refresh to your browser because it can be problems with cache)

Recommendations(practically obligatory)

  • Make a save (Backup) of your database and your file (especially the uploadsfolder), because the code have to update the database and deletion of files that are irreversible,so if something goes wrong is better have a backup.
  • Performs tests on any page other than your own default, but having the same characteristics, since I have not tested for compatibility with other plugin, so you can see if will work fine
  • Download this plugin only

known Issues

This plugin repeatedly uses the session variable, so problems can occur with another plugin, if you see this message, it is likely that the plugin does not work properly

And if you try to delete a file and get this message, definitely this plugin does not work

The problem is, that something is deleting data stored in the session, so I mustchange several lines of code so that functions well.

  • lisa

    where can i download this plugin

  • lisa
  • sean

    any chance of getting this working on WP3 multi site installs? It only seems to work on the main site in a multisite network install. i.e it works on but not


    • nicearma

      Yes, this weekend i going to try to adapt the code for multi site

  • Dmitry

    Can you add an option to select all files instead of selecting them one by one?
    Thank you,

  • nicearma

    sorry i going to work in this plugin, but i was very sick, i will make change for put a button for select all and code for work with multisite, but first i have to feel better

  • Dmitry

    Sure no problem, I hope you get better soon :)

  • Darkness

    I tested the plugin on my site as I have literally thousands of unused images. Doesn’t seem to be working properly as it’s deleted images that clearly were in use on pages.

    • nicearma

      Do you have or use other plugin for images? Like i explain, this plugin search if the image is used in any post and page, is easy see if the plugin going to work because only you have to go to any post or page and see en the part html if the image is referred like the name
      For example the image


      have to be referred like

      example15x15.jpg‘ >
      if you dont find this type of code html in your post or page, this plugin is going to fail, thar is why i’m asking if you use plugin, because i see plugin who use another type of logic

  • Pingback: DNUI Delete not used image | Best Plugins - wordpress – widgets – plugin 2012

  • nicearma

    @Dmitry Add button for select all, @sean i promest to work this week in the multisite option, i was seek two time

  • A.H.

    No, doesn’t work. Whatever I try to do – I always get
    There are total 0 images found
    There are total 0 images used
    There are total 0 not used images

    Is there anything else that can be done?

  • Vladimir

    Same as A.H , on the site whre I know for sure that I have at least 3 000 not used photos (big connercial site) plugin reporting total of 0 unused / found. I am chmoding folder uploads now, to 777, maybe will help.

    • nicearma

      @vladimir Don’t do that, the plugin before was working scaning the dir, but i change that, and now the plugin take the information from the database only, i’m working to put the 2 logic together.
      @vladimir and @A.H But is weird because like i said, at this moment the plugin take the information from the database only, if you want we can speak for take a look to the database and the site, but you have to send me information like user and password or maybe send me one backup of your site withe de database for do test in my computer, but like i said only if you want, if you want please do that, let me know(don’t put your information here, is for send you an email for speak better)

  • A.H.

    I’ve tried it lots of diff. way – no, doesn’t want to work.
    Here’s my screenshot

    • nicearma

      I think know will work fine, i was a sentence in the query sql(i did only one mistake, but that was enough)
      the problem was in this line

      $last= ‘ ORDER BY `wp_postmeta`.`meta_id`'; (could only work if the data base was with “wp_” so i change to generic query)

      $last= ‘ ORDER BY `’ . $table_prefix . ‘postmeta`.`meta_id`';

      that is why dint work with multisite to, please let me know if work!

  • A.H.

    It seems to finally start working, thanx a lot. But I’d also recommend make the results appear in different colors, as disabled checkboxes are not so obvious. So I’d recommend that images that cannot be deleted be shown in red colors and those that can be removed shown in green.

  • Vladimir

    Hey, somehow its working! GREAT RESULTS ! One of sites had 7611 photos on ftp, and 150.55 Mb size. After cleaning – 1543 photos and 51.55 Mb size. GREAT! Thank you so much man.

    Regard and big props

  • A.H.

    No, I was wrong – it still doesn’t work. It detects all child attachments and gives me an option to delete them, but when I select images to be removed and press button delete it says “This file appears not exist, that is why the plugin update the database”. But when I connect via FTP and go to that folder I still see that image EXISTS, plugin just fails to delete them.
    I can make screenshots and mail them to you, if you need more details.

    • nicearma

      Please try do this
      1 – Make a empty post and Upload one image
      2 – Go to the plugin (DNUI) and search the image upload
      3 – Try to see one of the image child(the version imageAAAxYYY) in the server with the link View (don’t close the window after)
      4 – Delete one of the image child(the version imageAAAxYYY)
      5 – Try to reload the window make in the step 3 and also in the server with your ftp program

      If in the step 3 you can’t see the image, the plugin have problem with the route, and that is why i s i have that problem in this blog with the new image, because now i use in this blog one plugin of amazon s3, so the route is out of the server.

      If you can see in the step 3 the image, go to the step 4, if in the first time came with the massage “This file appears not exist, that is why the plugin update the database” is rare, because is use the same route for see the image (only think this can happen if step 3 fail).

      If the step 4 says image deleted, please go to the step 5, if reload and you see the image. wait some time, because sometime take time to the server process the delete (why i dont know why, is something with the php function for delete file), if after sometime the image file exist is because the function php dont work fine and i have to see in the manual php how to fix that.

      Please let me know, which step fail, and i will put a function for search image who aren’t in refered in the database but exist in the server.

  • Richard

    Does not work. Deleted images that were in use. Thank god I backed up.

    • nicearma

      Please read!!!!!!

      Make a save (Backup) of your database and your file (especially the uploadsfolder), because the code have to update the database and deletion of files that are irreversible,so if something goes wrong is better have a backup.
      Performs tests on any page other than your own default, but having the same characteristics, since I have not tested for compatibility with other plugin, so you can see if will work fine

  • xphunt3r

    This is really very important plugin but needs more improvement. I manage to delete around 110MB unused image file from upload folder but still there are some unused images. I run 1000 query and got impressive result over 3000 unused images, i don’t know how it did search 3000 images with 1000 query search, i select all unused image and deleted it. Working great.

    Thanks for your effort on this plugin.

  • js

    I ran this my test site and boy I’m glad I did. It deleted all of the images I’m using. I had a feeling that there would be an issue because I use another plugin that puts the images in a non-standard location.

    What I’d like to see is a plugin that scans all of the html and databases for image references and then deletes the image files that are not referenced anywhere in the code. I’ll keep looking, but thank you for your effort.

  • basti

    I’ve used this plugin and it works great. Thanks for all the efforts!

    I realized that the “Select All” button just deletes the unused “son” images related to the father, but not the unused father images. Why is this? I still have several thousands unused father images and now I need to click all of them by hand. Is there a way around this?

    Thanks again! Great plugin and it works much better then most of the others around there – especially with large image collections like my blog!

  • Thomas

    Hi Nicearma
    I really liked the idea of this plugin and finally got the time to try it myself today. I know for sure that there is a lot of images on my server in different versions that are not used on my blog.
    Unfortunately I ran in to some issues. The plugin is also deleting images that are in fact used on my blog (Good thing I had a fresh backup). I noticed that it deleted both image on my front page and images from galleries. I don’t know if it has something to do with my theme.

    My blog is running with these versions:
    DNUI: 0.8.2
    Wordpress: 3.4.1
    Arras Theme:

  • Pingback: Finding & Deleting Unused Image Files In Your Media Library

  • Food Frenzy

    A recommendation to improve this plug-in is to have it validate if the image is selected as a featured image in a post. I am finding that every image on my site is coming back as erasable.

    Love the plug-in idea, but it falls short in identifying the correct images to show as erasable.