Remove Duplicate Images from Wordpress Database - Media Library Settings
HTML-код
- Опубликовано: 29 ноя 2024
- I cannot stress enough how Wordpress will create duplicate images each time you add to your Media Library.
This will bulk our your backend Wordpress Database - and IS NOT GOOD!
Even if you change the Wordpress Media Settings, and add this Code Snippet: websquadron.co... - then Duplicates from Previous Images will still exist.
Let's sort it out - and clarify what happens at each step.
See this Page that contains 1 Image in the Database and ensuring that no other size exists in the Database - staging14.webs... - view this on a Desktop or a Mobile. BUT Please do test on your own Test site.
WATCH IN FULL and Please SHARE because this hidden issue unless dealt with - can hurt your file-size.
We love to create - share - respond - and deliver.
🧐 Learn with our Mastery Modules: websquadron.co...
🔗 All of our Important Links: websquadron.co...
😃 Join our Facebook Group: / 3309523509284305
😃 Get Code Snippets Pro: r.freemius.com...
😃 Get Elementor Pro: be.elementor.c...
😃 Boost your RUclips Analysis: www.tubebuddy....
👕 Get our Merchandise: websquadron.co...
🥹 Support us: paypal.me/Webs...
Hire us to work on your Website!
💌 info@websquadron.co.uk
👩💻 Visit websquadron.co.uk
Excellent, this should be mandatory viewing for everyone starting wih Wordpress, just wish I would have watched this 2 years ago. I just finished deleting ~5000 images! Some of my images had over 30 iterations! Nuts!
I've recently tried your zeroing out the images, as you suggest. The problem that I have is that my customers tend to ignore their image file sizes and load very large file sized images. Then they add this image to a page or post and they have no choice but to use these huge images, even if they set it to thumbnail, medium, etc. They think that adding an image and it fills the column (maybe 33%) that the image is now shrunken to fit that space - but that image is still the huge image that they loaded.
I set those media sizes to: 250x0, 450x0, and 1024x0 - this will control the width and and the proper aspect ratio (height). I explain to my customers that they should use the smallest image that just fills the space, a thumbnail may not fill the space but a medium size will. Thanks... I do appreciate all that you do!
That’s a good point that you make
Would you create 1 medium image size for ALL units? (Tablet, mobile and desktop)
With the ratios you do in the settings, doesn't that create duplicates? The 250x0 one's etc.
Brilliant. Funny I bumped into this last week. One easy way I found to cleanup the media library is download all images locally from the site (I use Filebird and I think the option comes from that plugin), and that only gets the full images. Then erase everything through file manager and re-upload the images. As I (like you) don't use the year/month/day classification, media path are not changed and everything is fine.
Can you re-iterate that? I'm a little slow:P
Did you manually delete ALL files from media library from within wordpress?
And after this process, did you use and code so duplicates won't be created?
See this Page that contains 1 Image in the Database and ensuring that no other size exists in the Database - staging14.websquadron.co.uk/ - view this on a Desktop or a Mobile. BUT Please do test on your own Test site.
Hi, Imran. I would disagree with some things mentioned in this video.
1. The media cleaner plugin is not something you can trust. It is not that it would be 99% correct. The plugin cannot check the CSS and see which images are used as backgrounds, so you lose all those images.
2. You say copies, but WordPress does not actually create copies of the images. Just different sizes to use when needed. And by disabling this feature you may save some space from your disk, but actually you will use the full size of the images in the pages, and in carousel, post grid and other sections. So you will end up with bigger page sizes and that means bigger loading times.
3. The extra image size that you get when setting the 0 Media > Settings is probably coming from your theme. Other themes may create more sizes. Try a newspaper theme and do the same process. You will end up with a website full of placeholders instead of images.
4. There are plugins that will create different sizes as well, WooCommerce being one of them. And you will end up with more problems when you start deleting images or disabling sizes.
5. There are many themes that are bad at image size handling. Newspaper is one of them. They create over 20 image sizes of each one you upload. There is a solution to identify and only enable the sizes you need, but you will still need some of those. So basically use a better theme.
6. If you end up setting everything to 0 there is a far better way to delete the different image sizes. Use thumbnail image's regenerator. It will delete all the images that are disabled.
Overall, I would not suggest setting everything to 0 and delete all the image sizes. Those images can be used across the website for many reasons.
As always thanks for the video Imnar. Take care
No probs and thanks for the feedback.
Thanks for this comment. I might just have saved myself a little bit of headache. Perhaps just need to let certain things be.
@@websquadron Delete you video! You are destroying other peoples websites in your search to become a youtuber! DELETE IT
A follow-up... A lot of this can be solved by using WEBP. I'm now using EWWW Image Optimizer which does a great job of converting to WEBP. And a bonus, it does image sharpening(!). I'm now using sizes: 360, 550, 1120, 1920, and full. Using WEBP, most of these have file sizes at around 50k. These are the sizes that work best with the default 1140px width. And, a final quick comment, if you use the Elementor Hello theme, that has an option set: $content_width = 800. That setting will max out, to 800px wide, any media setting above the 800. If you set Large to 1020, it will only display 800. Took me two days to figure that out... painful!
Thanks
What about retina screens?
I feel lucky to have seen this video while im still building my website. Thank you!
Two things... Firstly, sometimes having small versions of images is a good thing if you have a blog. You might want the large image to appear as the featured image on post, while a smaller version appears on the archive page. Secondly, you kept saying database but it's really the uploads folder. The first two images that you uploaded and then deleted from the uploads folder are still actually in the database as paths to the images within the uploads folder. Just to clarify. I'm definitely going to be using this technique but will need to think about smaller images for blogs. Thanks!!!
It’s one of those weird techniques where there are pros and cons for using it. It’s a pity that WP have removed some control or not made it explicitly clear to users about the amount of images that get loaded into the uploads folder. Be careful when applying anything you’ve seen here.
Agree - deleting images from Upload without taking away the path from database is a recipe for future issue.
Damn. I think this should be a must watch video for anyone trying to build a wordpress site.
I was able to solve the problem. I hadn't noticed that there was a setting in the settings to show the code or not. I just set it to "Hide" and everything was fine with that... Thank you very much for your prompt reply.
Where did it 'hide'?
I changed the Media setting like you showed and I added the snippet code also. However, the code snippet is not making any difference in my situation. After changing settings and adding snippet, I still get copies in 100x100, 1500x824, 1536x844, and 300x165???/??????
Me too. I mentioned this on another more recent video like this and the code snippet doesn't seem to work for me either. I'm using Astra as a theme, zero'd out everything and it doesn't work. Imran, do you have any other suggestions?
Hi Imran, thank you for the never ending knowledge. Are you using this method for every website you build? Or are there instances where this wouldn't be advised? Thanks
When you know the site will be really heavy with images then cleaning up duplicated images can help you reduce the database size.
@@websquadron Sounds great. Cheers!
Thank you very much! This was very helpful!!
How am I just seeing this! Thanks, a lot
A simpler option would be to add the snippet code below, there is no need to set all the variants of the media settings to zero.
add_filter('intermediate_image_sizes_advanced','stop_thumbs');
function stop_thumbs($sizes){
return array();
}
Thanks my friend, with yours code working! Any solution how to delete the old Duplicate Images from database? It's thousand.
Pana so shall I just copy this into the snippet? is that all that is necesssary for your method? Or can you copy and paste the code you use into this comment so we can do use the same... Nice one!
Thanks. This worked for me but the code provided in the video did not.
The code in the video works for many, but alas, not for me. Your code snippet does, @pana_____ . Thanks a bunch to both of you 🙏
Ooooh thanks a loooot
Imran, if I could give this video a 2xthumbs up I'd do that. This was a great time saver / website database size save for me.
Always be careful when deleting images :)
Thank you for your tutorials.... Does this effect the size needed for a container or featured image, or would I now have to upload the exact size needed?
No but some people don’t like to remove them in case there is an issue.
Hey Imran, we can delete all extra images sizes files via cPanel BUT in the sql database the path images records are still there right? Any snippet to delete from database too? Great work!!!
Always be careful when deleting images :)
Yes you are correct. Paths to images are still within the database taking up space in there, especially if the image isn't used anymore.
@@BrockBarr Does the paths take up space/clutter directions? How to delete the paths?
This is awesome thank you,good timing too as just started a real image kick for my blog. I would like to see you do a video about code or other stuff remaining from theme changes and how to detect any of that
Hi Imran. Is that smart to do? There was a reason for WP to create 3 variations: for the 3 device sizes. Is it smart to load the full image on a smart phone? I'm just about to redesign a website with a heck of lot images, so I have to decide wether to follow or not your advice. Thanks bro.
I'll be putting out a URL shortly that only uses the one size to show it's fine
See this Page that contains 1 Image in the Database and ensuring that no other size exists in the Database - staging14.websquadron.co.uk/ - view this on a Desktop or a Mobile. BUT Please do test on your own Test site.
Sorry, so what if the 100x100 or whatever value/size images are being used on the front end? They won't get automatically replaced by the original, would they?
The original would be used so best to be careful with what is or isn’t used
Super-practical vid! Thanks. Two questions, though: Don’t the different file sizes exist for a reason? … often created by image optimizer, to use a smaller version in an archive grid, compared to the image on a single post. Second question: is there any reliable way (plug-in?) to determine which images are actually used on the site?
I have been dismayed by some plugins that age meant to find when an image is in use or not. As some may think that an image is not in use even though it’s used as a container background image.
Agreed that you have to weigh up why an image is a certain size especially for WooCommerce
I have found too that if I use the media library list view it often tells me am image is not used yet I know it is,is there a better way of telling where an image is used without using a plugin,I try to keep plugins down to bare nessicities
It’s a tricky one and no process is foolproof and some plugins will still get it wrong as to if an image is in use or not.
Thanks for the tips! I zero'd the media settings and created the snippet you provided but I'm still getting a couple of "extra" sizes. Another commenter here, @pana, posted snippet that worked perfectly. I uploaded 1 image and that's all that was created in by dB.
Yeah!!! Super awesome i was using a plugin for this!!! I will put this function into my Bricks Child Theme.
I have a 19GB photography site where the previous theme I used created 8 different versions of thumbnails. Is there I quite script I could run to just delete all of the sizes it generated? It's tens of thousands of images and the manual option would take days.
I’ll be sharing some code shortly
@@websquadron that's amazing! will it be a youtube video?
Hi,
Can you explain how to create a custom filtering options on the media library, using code snippet. I could see the name of the post to which my media is attached to, but not able to filter all media attached to a specific post or page. Can you help me with that.
That’s not fully doable as it can cause issues with the backend Wordpress in how it searches
@@websquadron my requirement was to remove files that are uploaded by user on a periodical basis. All these files are getting dumped into my wp media. If I could filter based the page /post through the users uploaded the media, I could select them all and remove them after downloading.
If a permanent filter is not possible a temporary filter also works. Whenever I want to perform this filtration I can activate the snippet and deactivate after my job is done.
Otherwise the filter parameter can be added to the url after '?' for the query result.
I've seen people asking on the WordPress community to filter media based on the author. But I couldn't find anything that I really wanted. Hope you can help.
So what do you do if the images are already put on the website? Do you take them off and then add them again after changing the settings and adding the code?
You could do that, or just delete from the database
Why it does not work with my website and even dupplicate more copies, please help!
Who is your host, have you asked them? And are you definitely deleting?
what is the best way to remove unused image with or without plugin? not duplicate one. My client has around 12000+ images where around 2-3k images are using in live website. how to delete the rest of the images
That will take a while to weed out unused images
Somehow after I did all the settings, when I check in cPanel file manager, it still creates 2 (sometimes 3) more copies of the initial image I upload (webP). Can you help?
Wordpress can still create more and that's a pain
I have added the code using code snippet plugin and done all the settings as you have shown in the video. Afterwards, I added an image to the media library. I can see total 8 versions of the image inside my file manager. Please help.
I can only help as part of a 1-2-1 consultation
is there a way to stay only with specific size (large 1920) but without the full size resolution, when i say full size resolution i mean if i upload 3mb image, i want to auto remove the 3MB file and stay only with large size... possible?
Only if done manually
@@websquadron it's a big real estate website that people are login and can submit their properties.. there must be a automatic solution to remove the full size after upload and after imagify finish optimize..
Hi Web Squadron. Is there a File Manager option in cPanel? Thanks!!
Should be there.
Log in to your cPanel account.
Scroll to the Files section and click on File Manager.
This will open the File Manager where you will be shown a hierarchical list of your main folders
but what do we do for the image widget responsive modes?
elementor doesn't let you have different images for mobile in the image widget.
only possible way to use a smaller image for mobile is the scaled images from the media settings
Trust me I don’t get no issue when I remove them but it is subjective so only remove if you are sure
I don't know why but this did not work for me. I added this codesnippet, it seemed to work in my media library and then got back to work thinking this worked. I just went through an insane amount of copies thinking this worked. What am I doing wrong. I also zero'd out everything as well and still getting 6 extra sizes. I have so many client sites I never knew this would be an issue and can't even bear to think how long it will take me to sort this out. Can you explain why this doesn't work, Imran? Many thanks in advance.
Difficult to be sure as I can't see your site?
@@websquadron yes, of course I understand. I suppose I should have asked, has anyone had a problem with the code? I did stumble on your more recent video this month (thank you!) and that one worked. I just am astounded in this frailty with WP. Why would anyone NEED as many multiples as is generated. I never even knew this was a problem until I watched one of your other videos about why sites get so bloated. Imran, you are such a great teacher and I also love that you’re so design focused.
What about the thumbmails i'm missing for my blog?
The category page where it shows small images for example: In this case it will takes the feature image? (which is big)?
Search results, archive, etc.
What would you recommend in this case?
Should I allow at least one duplication in a size similiar to what I need?
Yes, you do need to assess and check - however on testing, I could remove the 100 and 300 images and my blog posts were still fine - but do check
@@websquadron so if 100 and 300 were disabled, what images were shown on your blog?
@@thegate12345 See this: staging8.websquadron.co.uk/simple-presto/
The Black Friday Image is 1000 x 1000 and all other 100, 300, 768 size images are deleted from my SiteGround File Manager.
It still comes through on the post.
But - it is advised that you test this yourself with a Dummy post and an Image.
Doing this you will load "big images" also for archive pages or there is some workaround?
This is where you have to decide on what else you're using the images for, so if they are to be used for Woo Thumbnails or Archives then keep the relevant size.
Will WPMUDEV Smush or even setting the display size inside elementor still work?
Display setting size inside Ekementor does still work, but I don't use SMUSH so that would need to be tested out.
Yeah Imran thank you!!! Super awesome i was using a plugin for this - thanks for this video with the valuable infos!!! I
With anything - do still take care and make sure that you have a backup just in case
Is there a way of getting just 1 image on upload without any code? Why does WordPress create 2 images when the image settings are ticked off?
Where does the code go to? And will it be erased after updates?
I noticed copies are also made after editing an image. If you crop and save, that's another image. Then if you scale the same image, that's another image.
Yup it's almost never-ending
I tried the snippet but it's still generating all the sizes annoyingly. Any idea what it could be? I host my sites on Hostinger
Try and set everything to 0 zero in the image settings as he showed. Did you work this out?
@@audunjemtland8287 I did do all of that, while it doesn't show the different sizes inside wordpress, they are still being generated in my website files
me too, I did all the setting and snippet, but it still make 3 other files. confused. I use Hostinger too
what a useful video ... thank you for this video.. I'm using ligtspeed webserver I should learn how to do it.. it's another question for me 😂😂
DEAREST IMRAN, now I am upload woocommerce at 1000 by 1000 usually sometimes less or sometimes more... I see in the code you have not included the size small, is that because you upload small 500px by 500px or is that all irelevant my friend? And shall I just go ahead and copy the code and your method? for my 1000by1000px.... You the expert, do advise, you the man Imran
Test it out as it depends on the site, but I would suggest leaving the 500 x 500 in.
Once cleaning up the images, how does this effect page load and gtmetrix and Gpage speed?
This is more for your backend database size
@@websquadron so, on the front end, it will not effect anything?
No
@@websquadron I just cleaned up about 500 megs on my photography website. On my gallery page I just had to go back in and save the page because some of the images wouldn't showing right. Thanks for the tutorial Hope to see more soon.
Good morning...
I did everything the same as your video, but the images are multiplying on the server.
Have you disabled the Media Image Sizes in Wordpress Settings > Media?
@@websquadron yes
Hi can you make a tutorial for images randomly dissapearing in wordpress ?
Is this after you have cleaned up or run some optimisation?
i dont know but i cleaned my cache any everything but it still dissapears even if i reupload them @@websquadron
im using ghl + wordpress@@websquadron
Hi, I've tried this custom php code but wordpress still generates images as 1536x987 and 2048x1317. Why could be it?
Any plugins or optimisation image tools loaded?
@@websquadron I use Elementor and Wp Rocket
I think if you add the snippet and install the plugin regenarate thumbnails it will remove the other generated images
I'll have to try that.
Hello, I think it is working but why is the code shown on my website-heading? I have a screenshot...
That is very strange. Are you adding it to Code Snippets?
I guess you also recommend using the Full size of images for example Elementor's Posts widget, Woocommerce grids etc? (Goes without saying the images need to be optimized before uploading) :) edit: Sometimes pagespeed analyzers complain about image sizes with such widgets though, but just ignore them? :D
I add them in, and then resize accordingly inside the Media Library. For instance, I always size Woo images to be 500px x 500px, and others can be variable as I may decide on the exact size when building on the page.
See this Page that contains 1 Image in the Database and ensuring that no other size exists in the Database - staging14.websquadron.co.uk/ - view this on a Desktop or a Mobile. BUT Please do test on your own Test site.
thanks a lot
Hi Imran .. Are you Okay man ? what happened to your hand I'm worried bro why you use these ?
Hi - I was wearing gloves for warmth:)
@@websquadron ohhh.. Okay ! We have warm rainy weather here in Madinah, Saudi Arabia
i still get 3 sized images when i upload one :( 100x, 300x and 600x). :(
Even after you add the Code Snippet and Change your Settings? Also make sure that you rename the image before uploading it, just in case.
@@websquadron yes all done but still, the moment i upload new fresh image, i always have my original one and the other 3 versions. Maybe it's because of some settings in the other plugins idk but hard to find the culprit. I don't have so much plugins on my site, will figure it out!
@@danjepi82 have you cleared the server and site cache? just a thought
@@visualmediafx thanks and yes yes of course
I thought the thumbnail was created for the media library?
Funnily enough - not always - unless it's a WooCommerce Image. I've removed all 100x100 sizes and my images still show.
@@websquadron Interesting, but what about media library loading times without these small thumbnail images?
@@angelaschmidtdesign932 I don't have that issue, except with WooCommerce in the library where removing 300x300 can affect the library. But not with my normal images.
Ah, just what we need. People screwing up their responsive images by zeroing out their thumbnails.. :/
These do have a purpose.
Yup