Sort and delete unused images (speed optimisation), need advice

  • This topic has 3 replies, 1 voice, and was last updated 1 week, 2 days ago by GlitchyDragon65.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #5733

    With my colleague, we are in a site speed optimization period, deleting unused plugins, calling scripts only where they’re need etc…

    Now, it’s time to gain space with images. Our WordPress has hundreds of pics but, we need juste 30-40% of them. I know that plugin exist but :

    * little bit scared to let plugin delete things in the database
    * personal challenge !
    * trying to understand a little bit more how WordPress works


    So I search how to do that myself and set up few steps.

    1. Sort used and unused images
    2. Where and how delete unused pics in the database
    3. create a new uploads folder with only the pics we need


    I have created a script that performs all these steps (you can look and try it on my Github > []( )

    Everything works, the script creates a new uploads folder and a SQL script, but I’m still doubtful.

    The next step is to execute the SQL script on the server and replace the uploads folder, I’ve tried it locally and it works, but stay a little bit scared to do that on my company’s web site ^^.

    I still hesitate to fell very smart and proud of it or the total opposite, can you guys tell me what do you think about that process and if you think that it will works ?


    If you are interesting to update my script or giving some tips, I will be glade of this


    Seems like you’re on the right track but why are you copying the used images to a new folder? Your SQL scripts don’t update their paths in the database so it seems this step is redundant.


    Always happy to see new development, but if you decide to go with a plugin in the end, this one has worked well for me. It puts deleted files into a temp folder, so that if stuff is missing from your site, you can restore the files before deleting them completely.

    Media Cleaner – Clean & Optimize Space


    If your using wordpress use should use Smush or else you can see the source code by downloading you can search at

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.