Delete Unused Images from WordPress Media Library

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 135

  • @websquadron
    @websquadron  6 днів тому +9

    Updates:
    1. Code updated to detect Background Images
    2. Code updated to detect Site Icon
    3. Code updated to detect Favicon
    4. Code doesn't append delete_delete_etc each time you run/search for delete :)
    5. Button added so you can remove the prefix delete_ as you may not need them now :)
    6. It now covers Product Categories too
    If you can make this code even better - send it to me - so we can update the current code. This is the start - but some of you will spot gaps so get cracking with your coding. And remember - if you don't like it - don't use it. Stay safe.

    • @Digital-view24
      @Digital-view24 5 днів тому

      by the way, im getting "Error 400: redirect_uri_mismatch" when trying to login using my gmail account to get the code

    • @websquadron
      @websquadron  5 днів тому +2

      @@Digital-view24 www.codesnippets.cloud/snippet/WebSquadron/delete-unused-images
      Works for me. Did you click or copy the link

    • @fredvictor6890
      @fredvictor6890 3 дні тому +1

      Nice work but, highlight a lot of images which are in fact used ! for exemple images used by Slider ( slider revolution) are not identified as used image. So it take pretty much the same time to check all highlighted images before deleting any. At least it is so for me, by chance I did it only on staging to try and have been back to backup after deleting pretty much all my images ;) I mean, the unused concept is not good enough to be really useful in my case.

    • @websquadron
      @websquadron  3 дні тому +2

      @@fredvictor6890 It's useful for quite a few but I accept that it's not great for every scenario. The code is there to be built upon and I look forward to seeing what others do with it :)

    • @fredvictor6890
      @fredvictor6890 3 дні тому +1

      @@websquadron fair enough ! :)

  • @Digital-view24
    @Digital-view24 5 днів тому +3

    Another Code Snippet Magic... If I count how many times you have saved me with your code snippets Codes!!!!! You are a Gem in this Industry... Thank You millions

  • @HossamKhalaf-sr1oo
    @HossamKhalaf-sr1oo 4 дні тому +1

    tested on staging site first, then on live website, works perfectly and deleted 600 unused images
    Great thanks Imran

  • @KillahManjaro
    @KillahManjaro 3 дні тому

    Perfect timing for this code snippet.
    Your info has always come at the right time.

  • @budadams412
    @budadams412 6 днів тому +7

    This is great! One step further, there's a bulk download plugin that would allow you to download all the "delete_" ones, and you can offline archive all the images prior to actually removing them from the site (especially if it's a site that you inherited and don't have 100% familiarity with). Cheers man!

    • @PsyMyself
      @PsyMyself 6 днів тому

      Hum that's a good idea. ...i will use our friend chat to see the code for that

    • @paul701
      @paul701 6 днів тому +2

      Yes - a bulk download of the marked images as an archive before hitting the 'delete' would be awesome. Removes the stress of making a mistake.

    • @Tom59Kriek
      @Tom59Kriek 5 днів тому +1

      Are you saying there is such a plugin, or would it be nice if there was one? If there is one, what is it called? I do not see something obvious?

    • @budadams412
      @budadams412 5 днів тому

      @ Media Library File Download
      By Calculabs

    • @SmithyProductions
      @SmithyProductions 4 дні тому

      Interested in this as well. Is there a plugin?

  • @QuaverloveStudio
    @QuaverloveStudio 5 днів тому

    I'm just here grinning.... I love when you get excited about a solution!
    Hats off, Imran. That's an amazing utility!

  • @evanhodson5533
    @evanhodson5533 6 днів тому +2

    This is genius! One less plugin to have to use. Well done Imran!

  • @robsloan8
    @robsloan8 6 днів тому

    Worked so smoothly, thanks Imran. from 1000+ photos down to 300. happy days.

  • @johnburns5424
    @johnburns5424 5 днів тому +1

    Absolutely brilliant Imran. Been looking for something like this for ages. A town council arts website I host has over 2000 images now down to less than 400 after checking that none are recent and not being used on a test site. Now off to do the real site. Thanks for your extraordinary work you do for no gain.

    • @johnburns5424
      @johnburns5424 5 днів тому

      Imran, Are you able to check that images used in JetEngine Post Types Gallery are not affected as think it may have deleted some as just getting a place holder now. Did not notice this before as only a few posts exist using that method and forgot to check. Not a problem as still on test site. Thanks.

  • @harveyhoffman963
    @harveyhoffman963 5 днів тому +1

    Worked perfectly! Cleaned up a few hundred unused images. Thank you!

  • @phkoon
    @phkoon 5 днів тому +1

    Thanks, man!
    I was to sort this out for a while now, but with so many stuff to do prior to it, just hadn't gotten to it yet; now you just delivered it...

  • @MatthewFurman
    @MatthewFurman 4 дні тому +1

    Imran, you are incredible. Thank you for such a great video.

  • @marekrabiasz1175
    @marekrabiasz1175 5 днів тому +1

    Dziękujemy.

  • @lucylink7975
    @lucylink7975 3 дні тому

    Oh wow! Thanks Imran, this is amazing. Off to spin up a staging now and see what I can do for my image-heavy sites. Awesome.

    • @websquadron
      @websquadron  3 дні тому

      Might give false positives if images are added via other plugins or stuff but you’re in control over what you remove and it now comes with an extra button to remove the prefix too

    • @lucylink7975
      @lucylink7975 3 дні тому

      @@websquadron Yes, I'm just experimenting. Looks like it is not seeing my images on JetEngine galleries which are displayed via a template on custom posts. So definitely needs to be done manually. The other thing it is possibly not catching is images loaded in things like popups. And maybe, I'm not sure yet, where I've got different images loaded for mobile or tablet view. But still very useful. And easier than guessing.

  • @dangerdanj
    @dangerdanj 5 днів тому

    I’ve been praying for something like this. Thank you!

  • @pattipeilohyg
    @pattipeilohyg 5 днів тому +1

    This is genius Imran!!!!!

  • @Graphdevigner
    @Graphdevigner 6 днів тому

    Great solution Imran! Thank you for your amazing work!

  • @alexpearson6991
    @alexpearson6991 5 днів тому

    What a legend, thanks so much for this!! I just took on a simple WP website that is 1GB in a size. You can guess where the space is taken up...yup..old images and loads of them.
    Time for a staging site 😊😊
    Thanks again!

    • @websquadron
      @websquadron  5 днів тому

      Hope it works for you.
      Note that duplicate images in your wordpress files may still remain.

  • @ashrafkhan7386
    @ashrafkhan7386 6 днів тому

    Exactly what I needed. Thanks, Imran.

  • @user-hv3ud6et3c
    @user-hv3ud6et3c 4 дні тому

    Oh my god, literally, I was looking for this.

  • @graemeclarke1942
    @graemeclarke1942 6 днів тому +1

    Great job, thank you!!

  • @umairyousafzai07
    @umairyousafzai07 6 днів тому

    Just awesome Man ❤
    You're a life savior 🙌🏻

  • @visualmodo
    @visualmodo 5 днів тому

    Really good work!

  • @KaiBuskirk
    @KaiBuskirk 6 днів тому

    merry christmas!!!
    kai

  • @realstudiositalia7495
    @realstudiositalia7495 5 днів тому +1

    Thx Imran! big up

  • @bobbypalmer2460
    @bobbypalmer2460 6 днів тому

    Imran, shear magic - thank you

  • @elcondorito8823
    @elcondorito8823 5 днів тому +1

    Cool ! Thanks

  • @soulesperanza
    @soulesperanza 6 днів тому +1

    good one!

  • @kithallows7125
    @kithallows7125 5 днів тому

    Thank you so much!

  • @JosephRosenstock-e5j
    @JosephRosenstock-e5j 6 днів тому

    This is so genius!👏

  • @digwillhachi
    @digwillhachi 6 днів тому

    very interesting. I will give this a try on a staging site.

  • @LucyVozenilek
    @LucyVozenilek 5 днів тому

    Thanks Imran. This is really good. I need to create a staging site to test this. However, with the default settings, when you upload an image, Wordpress creates 3 variations (Large, Medium and Thumbnail). I have an old site built with Enfold which actually creates 14 variations (and you have no option to change this). A shortpixel optimised image upload (67KB) takes up 3.887 MB with all the variations. Two questions: 1. When deleting an image, does the snippet also delete the variations? 2. If you ARE using an image, could the snippet delete the variations not in use?
    As always, thanks for everything you do.

    • @websquadron
      @websquadron  5 днів тому +1

      Variations may still exist but you should add this snippet to just keep the original and the thumbnail: ua-cam.com/video/ceQv9FgIZmQ/v-deo.htmlfeature=shared

    • @LucyVozenilek
      @LucyVozenilek 4 дні тому

      @@websquadron and therein lies the problem. Even when you disable these settings, Enfold still creates additional versions. There is no way to see these other than viewing them directly on the server. So how do you remove old unused images and their unwanted variations? Or unwanted variations of images that are in use? Perhaps that's a 2025 challenge for you :)

    • @websquadron
      @websquadron  4 дні тому +1

      @@LucyVozenilek Not a challenge for me :) Too many variables to handle and too many alternate tools. I always use manual processes to handle my webp images, and ensure I have this snippet activated to stop duplicates from the get-go. For legacy sites you have to manually delete from your WP Files and Databases. Never fun :(

  • @robertorosello5861
    @robertorosello5861 6 днів тому

    Brilliant !!!

  • @pavelstanczuk
    @pavelstanczuk 6 днів тому

    Truly time savior. Can this work for pdf files as well?

  • @tabithao.abiola7540
    @tabithao.abiola7540 6 днів тому

    Hi, I came upon the code to remove unused java script:
    //This has been syncronised 123//
    2function wp_remove_scripts() {
    3// check if user is admina
    4 if (current_user_can( 'update_core' )) {
    5 return;
    6 }
    7 else {
    8 // Check for the page you want to target
    9 if ( is_page( 'homepage' ) ) {
    .....
    After reading through I noticed that it only removes indicated java script on the 'homepage'
    To remove from entire site can the individual pages be listed separated by commas and quotes is there is another way to do it?
    Thanks.

  • @hey-its-ashraf
    @hey-its-ashraf 6 днів тому

    I've used the snippet, works all good except site logo and favicon.

    • @websquadron
      @websquadron  6 днів тому +1

      That's the beauty of the code :) You can see what's not been picked up so you don't delete something accidentally. BUT - i just updated to make sure it identifies the Site-Icon and Favicon - note that it keeps the version/cropped version used :)

    • @hey-its-ashraf
      @hey-its-ashraf 5 днів тому

      @@websquadron That's great work, appreciate the attention to details. Thank you!

  • @jimroberts1248
    @jimroberts1248 5 днів тому

    Hamburger and Close SVGs used as dynamic tags in Off Canvas are prefixed "Delete."

    • @websquadron
      @websquadron  5 днів тому

      Any false positives can be ignored, but you also have the button to remove the prefix after you've dealt with the real Deletes.

  • @SpencerTaylorOnline
    @SpencerTaylorOnline 6 днів тому

    Brilliant! I love it!!!

    • @websquadron
      @websquadron  6 днів тому +1

      It may not work for some as sites can be very different so test on a staging site.

    • @SpencerTaylorOnline
      @SpencerTaylorOnline 5 днів тому

      @@websquadron of course!

  • @Jimsoda
    @Jimsoda 5 днів тому

    Tested on a staging site and worked great except for a container background slideshow. Did not recognize images as being used. This is something I have been looking for quite some time.

    • @websquadron
      @websquadron  5 днів тому +1

      Hopefully someone can advance the code. At least you know they are there so don’t delete them.

  • @MelTaylor
    @MelTaylor 6 днів тому

    Excellent. Media libraries get huge before ya know it. Scary to use some media cleaners. Gonna use Imram snippet solution

  • @pulp5618
    @pulp5618 6 днів тому

    Great! Can we have the same solution for plugins? In some of my big websites I've used a lot of plugins that I'm not sure if I've used them anywhere in my website and now I'm afraid to deactivate it

    • @websquadron
      @websquadron  6 днів тому

      That could take some work to get right.

  • @jaseyarm
    @jaseyarm 5 днів тому

    i tried running this on our site Imran mate, and an error occurred. i think it is probably because we have 32000 images. is it possible to get it to run in smaller batches you think, so it doesnt crash the server?

    • @websquadron
      @websquadron  5 днів тому

      I was working on a version that runs in batches, but will revisit

    • @jaseyarm
      @jaseyarm 4 дні тому

      @@websquadron superstar imran - i will keep an eye out, or reply to this comment when u get it done so i can test it. good night for the leeds fans last night

  • @RobCooper
    @RobCooper 4 дні тому

    Is this deleting all sizes generated or just the main image?

    • @websquadron
      @websquadron  4 дні тому

      Just the main. You need to have another snippet that ensures only main and 150x150 are created.

    • @RobCooper
      @RobCooper 3 дні тому

      ​@@websquadron We have 7 images generated. We need them all. We're a photography website and promote photography tours, workshops, sell products, have ads and backgrounds etc.
      We have galleries that expand on click to full screen size 2560x in a number of places too.
      I generate the proper image size for the place it's used for performance reasons. I have no issue generating the images.
      Im more curious about ways to find unused , through custom code, widgets, pretty much everywhere. I've looked into this many times and it's a complex issue (for us anyway). This functionality is on the HappyFiles Roadmap, but not out yet.

  • @sina_samiipour
    @sina_samiipour 6 днів тому

    Bro this is fantastic Idea 😍
    but I think it doesnt work properly with Imagify plugin and image optimizers

    • @websquadron
      @websquadron  6 днів тому +1

      That's a pity :( I haven't got the resources to check against all of them - but you have the code to build upon :) Some plugins modify the filenames when they are used hence it can become very subjective to identify them.

  • @ElfenHelden
    @ElfenHelden 6 днів тому

    this is faboulous, thank you. But I just tried it on my staging site and noticed that it's also marking product-category pictures which are in use for deletion. Can you confirm or is it just a bug on my site? thank you.

    • @websquadron
      @websquadron  6 днів тому +1

      Let me check that part. Hopefully you'll spot those and not delete them.

    • @websquadron
      @websquadron  6 днів тому +1

      I've updated it :)
      1. Code updated to detect Background Images
      2. Code updated to detect Site Icon
      3. Code updated to detect Favicon
      4. Code doesn't append delete_delete_etc each time you run/search for delete :)
      5. Button added so you can remove the prefix delete_ as you may not need them now :)
      6. It now covers Product Categories too

    • @ElfenHelden
      @ElfenHelden 5 днів тому

      @@websquadron you're so smart, thank you. That works. For some reason it does not detect pictures in my blog being in use and marks them for deletion. It's not a big deal, as I can check that manually. It certainly is exactly what i was looking for, because i have so many pictures blowing up my website. Again thank you so much for this great snippet ;-)

  • @wgm247
    @wgm247 6 днів тому

    Tried this - first thing the code snippet did was to pre-fix Delete for my homepage banner so failed at the first hurdle. The image was in an elementor slideshow.

    • @websquadron
      @websquadron  6 днів тому

      The code is the start :)
      One day it will be perfected by someone - but at least you know not to remove it. Plus the code gives an extra button to remove the Delete_ from the title for the false positives. Thanks for giving it a go.

    • @wgm247
      @wgm247 5 днів тому

      ​@@websquadron always like to experiment.. it's definitely a good starting point...

  • @NOALNOM
    @NOALNOM 6 днів тому

    This is amazing bro, thanks a lot!!!

  • @ericj5239
    @ericj5239 6 днів тому

    Do you have to register on the cloud link to get the code snippet?

    • @websquadron
      @websquadron  6 днів тому

      Yes as that's where I store the codes.

  • @jean-paulmesserli8269
    @jean-paulmesserli8269 6 днів тому

    Also Images used as back ground?

    • @websquadron
      @websquadron  6 днів тому

      Code updated to make sure it catches the Bakground Image too :)

  • @LanceMcGrew
    @LanceMcGrew 6 днів тому

    I must be missing something - doesn't work for me. I click the "mark unused images" button, see a screen blip, but nothing is marked delete. image analysis complete. Used Images: 1723. Unused Images: 48. Using Elementor Pro

    • @websquadron
      @websquadron  6 днів тому

      Which Page Builder or plugins are you using for images?

    • @LanceMcGrew
      @LanceMcGrew 5 днів тому

      @@websquadron Elementor Pro - 3.25.4

    • @LanceMcGrew
      @LanceMcGrew 4 дні тому

      @@websquadron Elementor Pro

  • @marc_hmv
    @marc_hmv 5 днів тому

    This didn't work for me. Deleted half of my used images - Elementor content, Elementor sliders, Gutenberg content - everywhere. Glad I followed your advice and made a staging first ...

  • @blackwidow526
    @blackwidow526 5 днів тому

    Unfortunately it doesen't work for me. Images were taken from the widgets gallery and image carousel was not recognized and therefore deleted. Good thing it was a test site.

    • @websquadron
      @websquadron  5 днів тому +1

      Always take care before deleting.

  • @websitetrainingpro4855
    @websitetrainingpro4855 6 днів тому

    Hi brother,
    I tried to test the snippet on a staging website. But it is picking the images that are being used in the IMAGE widget of elementor. Not sure why it happened.

    • @websquadron
      @websquadron  6 днів тому

      Do you mean it's not picking them up as it does for me?

    • @niralsura
      @niralsura 6 днів тому

      I assume he means images used in the Widgets or Image Module of Elementor. I will also try and update but our woocommerce site has 10000+ images.

    • @websquadron
      @websquadron  6 днів тому

      @@niralsura Test on a staging site.

    • @websitetrainingpro4855
      @websitetrainingpro4855 5 днів тому

      ​@@websquadron The issue is that the code is selecting the images used on the website and appending the word "Delete" to their names. Specifically, I have an image widget on the blog page that is populated with dynamic data. However, the code snippet is also picking the images displayed in that blog page image widget.

    • @websitetrainingpro4855
      @websitetrainingpro4855 5 днів тому

      @@niralsura That's right.

  • @DoubleLiu-w1r
    @DoubleLiu-w1r 6 днів тому

    Great idea, but unfortunately, it doesn’t work very well on my site. I’m using a third-party plugin with numerous option images, and this code highlighted many of them, adding ‘delete’ to the image file titles. So do check it thoroughly before bulk deleting the highlight images! I hope I can program so that get the code to better suit my site. 😴
    
    Anyway, thank you for the video. It seems the only option for me might be to manually delete the unused images one by one. 😭

    • @websquadron
      @websquadron  6 днів тому

      That's a pain. Which plugin are you using as it may be labelling them differently after it goes through that plugin.

    • @DoubleLiu-w1r
      @DoubleLiu-w1r 6 днів тому

      @@websquadron Extra Product Options

    • @websquadron
      @websquadron  6 днів тому

      @@DoubleLiu-w1r And do you know if that adds additional prefixes/suffixes to image titles?

    • @DoubleLiu-w1r
      @DoubleLiu-w1r 6 днів тому

      ​@@websquadron it adds like this (many delete in the front of the image title): Delete_Delete_Delete_Delete_AK_Head_LS5

    • @websquadron
      @websquadron  6 днів тому

      @@DoubleLiu-w1r Yes because you're running it multiple times.

  • @codenamepod
    @codenamepod 6 днів тому

    Doesn't work if you have a lots of images. Gets console time-out error. Good maybe for short sites.

    • @websquadron
      @websquadron  6 днів тому

      How many images did you have as I tested on another dummy site that had 632 images.

  • @thewebstylist
    @thewebstylist 6 днів тому

    Iman bro I wish you had a visual designer on your team so I could watch your vids all the way thru (sorry, you rock, but you cut so many corners on rushed showcase tutorials w no regard for proper visual best visual presentation) again I had to click away half way thru. Just being honest brah! 4:19

    • @websquadron
      @websquadron  6 днів тому

      Really? What was wrong here? Would you rather I was slower or took my time more?

    • @websquadron
      @websquadron  6 днів тому

      PS - which bit did I cut corners here?

  • @Tom59Kriek
    @Tom59Kriek 4 дні тому

    Naa, deleted all my background images. And that was after the updates.

    • @websquadron
      @websquadron  4 дні тому

      Interesting. Were the images in containers background. It won’t delete unless you manually delete them.

    • @Tom59Kriek
      @Tom59Kriek 4 дні тому

      @@websquadron Yes. You find the image in Elementor, edit container, style, background. I have probably 8 sections on the homepage all with their own background image. All the images were highlighted as not used and subsequently, I manually deleted them by searching for all 'delete', selecting them, and then permanently delete. No harm done, just restored my backup.

    • @Tom59Kriek
      @Tom59Kriek День тому

      @@websquadron I replied 2 days ago and I now see the reply went missing? Yes, the image is in the edit container, background, image.

    • @websquadron
      @websquadron  День тому

      @@Tom59Kriek mine don’t get highlighted but even it does you’re in control whether to delete or not

  • @MartinHeller8282
    @MartinHeller8282 4 дні тому

    Unfortunately, this does not work on my site (test site). I have created some CPTs with ACF.
    All my CPTs are “active and public”. I have checked it with:

    /**
    * Plugin Name: Post Types Overview Dashboard Widget
    * Description: Adds a dashboard widget displaying all registered post types, their public status, and post counts.
    * Version: 1.0
    * Author: Your Name
    */
    // Hook into the dashboard setup action
    add_action('wp_dashboard_setup', 'add_post_types_overview_dashboard_widget');
    function add_post_types_overview_dashboard_widget() {
    wp_add_dashboard_widget(
    'post_types_overview_widget', // Widget slug.
    'Post Types Overview', // Title.
    'render_post_types_overview_widget' // Display callback.
    );
    }
    function render_post_types_overview_widget() {
    // Retrieve all post types as objects for easy access
    $post_types = get_post_types(array(), 'objects');
    echo '';
    echo 'Post TypePublicPublished Count';
    echo '';
    foreach ( $post_types as $pt ) {
    // Count published posts for this post type
    $count = wp_count_posts($pt->name);
    $published_count = isset($count->publish) ? $count->publish : 0;
    echo '';
    echo '' . esc_html($pt->labels->name) . ' (' . esc_html($pt->name) . ')';
    echo '' . ($pt->public ? 'Yes' : 'No') . '';
    echo '' . intval($published_count) . '';
    echo '';
    }
    echo '';
    echo '';
    }

    This creates a table with “all active Post Types” on the dashboard.
    Do you know why some of the images are labeled “delete” even though they are “Uploaded to”?

    • @websquadron
      @websquadron  4 дні тому

      Variability kicks in with the different plugins.

  • @Floatnride
    @Floatnride 6 днів тому

    Nice work