Removing old thumbnail information from wp_postmeta

Jack Chan💻 Tech & CodingLeave a Comment

If you have wordpress building experience you know that whenever you set up a wordpress website, and everytime you upload an image, it will automatically generate thumbnails with different sizes for you. The intention for wordpress to do that is to serve a smaller size file whenever appropiate to save the network traffic. However, these days, you really don’t need to do that because jetpack has already provided a service called proton which will automatically resize your image.

Photo by Negative Space on

Because of that, it is actually safe for you to stop generating all the thumbnails. To do that, simply install a plugin called “Image Size” will help.

But doing so will only stop generating thumbnails for your future images upload. You can run the following linux command in your server to remove all the previously generated thumbnails. Be sure to backup your server before doing so.

find . -name *-*x*.jpg | xargs rm -f

That will remove all the previously generated thumbnails in your server, as all the thumbails are having the filename like image-1024×768.jpg

You will then have to search all your post for links referencing these thumbnails. A useful SQL query for you is

update `wp_postmeta` set meta_value = '' where meta_key = '_wp_attachment_metadata' and (meta_value like '%thumbnail%')

Finally, you still need to remove the registered thumbnail size for your previously uploaded images. If you don’t do anything about that, wordpress will still try to look for the thumbnails and if they can’t be found, your website will be full of missing images. These thumbnail size information are stored as metadata in wp_postmeta. Running the below command can remove that.

update wp_postmeta set meta_value = “” where meta_key = ‘_wp_attachment_metadata’ and (meta_value like “%thumbnail%”)

Alright, that’s it. If you are interested to know more about wordpress, you are welcome to enroll in my wordpress course. Cheers!

Leave a Reply