Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How To Bulk Remove Featured Images From Posts in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How To Bulk Remove Featured Images From Posts in WordPress

Recently one of our readers asked us how they can bulk remove featured images from posts in WordPress? At WPBeginner, we have discussed featured images (post thumbnails) many times. We showed you how to add featured images in WordPress, how to add new image sizes in WordPress, how to regenerate thumbnails, we even showed you how to add multiple featured images to a post in WordPress. In this article we will show you how to bulk remove featured images from posts in WordPress.

The Problem With Bulk Removal of Post Thumbnails or Featured Images

Unfortunately, by default you can only remove featured images by editing each post and removing the featured image. Now if a user has hundreds of posts with featured images, then removing them one by one can be a very time consuming task. Instead, we are going to try a different approach. We will run a database query and unset the featured images on all posts.

Before you proceed, please note that the code below will remove featured images from all posts on your WordPress site by simply just pasting. Also note that this code will not delete any of your uploaded images, they will still be available in Media Library and you can reuse them anytime.

All you need to do is copy and paste this code in your theme’s functions.php file.

global $wpdb;
$wpdb->query( "
    DELETE FROM $wpdb->postmeta 
    WHERE meta_key = '_thumbnail_id'
" );

That’s all. As soon as you save your functions.php file this script will run a database query and remove featured images from all posts.

Important: Please remove this code immediately after saving your functions.php file. You will not be able to set featured images in WordPress as this code will keep removing featured images from posts.

We hope this article helped you save some time and allowed you to bulk remove featured images from WordPress posts. For questions and feedback please leave a comment below.

Source: Kaiser

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Em says:

    Followed the instructions to the letter. Got this error message: Parse error: syntax error, unexpected ‘$wpdb’ (T_VARIABLE) in /home/ruznnjep/public_html/wp-content/themes/natalie/functions.php on line 411

    Blog broken. Had to reinstall. Thanks.

  2. Dan says:

    Thank you! It is an excellent advice to remove all featured images

  3. Jax says:

    Is there anyway to undo this? I didnt realise it would remove thumbnail images as well. I have tried restoring the thumbnails but it is not working. Thanks

  4. Mike says:

    #1. Are we 100% positive that the current code does NOT delete any images from my media folder? And simply “unset” them from featured image?

    #2. You mention “However, the query can be modify to exclude certain post types.” Can you share the code I would use to avoid a category with ID=25?

    Thank you so much,

  5. RaviTeja Adibhatla says:

    Works like charm. Thanks man :)

  6. Afzal says:

    Thanks Buddy… this is what i need … Thanks A lot for this helping tutorials..
    Love you bro

  7. srijita chattopadhyay says:


  8. Raakib Hasan says:

    This code remove the post thumbnails as well. But I want to keep the post thumbnail ( when it show grids on Homepage) and just want to remove the feature image from inside the posts. Is this possible?

  9. Luke Melbourne says:

    Awesome! Just what I needed. Thank you.

  10. Karen says:

    Thank you so much for this tutorial! It worked perfectly!

  11. Zaid Sparrow says:

    Hi, will I have my all featured images back on place after removing this code? or I’ll have to set them manually again?

  12. Abdul says:

    this is exactly what i was looking for but i have tried these and it’s not working for me.i am using generate child theme and on my home page some posts are still showing featured image.i also turned them off in genesis settings but nothing do i stop featured images to be shown on blog page?Thanks

  13. Irmina Santaika says:

    Thank you so much!

  14. Abhishek Mishra says:

    Sorry dude, its now working

  15. w0ngsimp4ng says:

    thanks its work :). I Have removed all featured image and rebuild again with auto post thumbnail plugin.

  16. Jeff says:

    I pasted the above code into my site with no luck. Is this thread still accurate and active?


  17. Marcelo says:

    After delete my related images my images from homepage desappeared, but when I go to post details it appears normally. Before run the script, the homepage used the images from inside the post and not from related images, so I really don’t know why they desappeared from my homepage. Do you have any idea why this happened?

  18. Robin Solanki says:

    Thanks a lot, you helped me saved a lot of time.

  19. Rahul says:

    Is there a plugin or codes to remove both post and images attached to a post when we delete it? I mean if i delete a post i also want to delete images related to that post also.

    • WPBeginner Support says:

      You will have to delete images from media library.

      • Rahul says:

        Wish someone would have made a plugin like that because deleting images from 100-200 posts is very time consuming… ?? if any plugin of that kind comes up pls do update it in ur site.. thanks for your reply

  20. Nicholas says:

    Is it possible to query a specific category and remove just those categories posts featured images?

  21. Biriisi says:

    Thanks man!!

  22. Justin Edwards says:


    I used this code yesterday to try to delete the featured images as part of an upgrade to a new WordPress theme. While it did delete the featured images from posts, it also deleted them from the media library and I think it’s also deleted the original files from the server.

    Having used this code to try and speed thing up, I now find myself having to re-install and re-link over 2,500 images for my site.

    • WPBeginner Support says:

      Justin, we tested the code again. It does not delete files from your media library or your server. It just unsets featured images.

      • Sudip says:

        I am facing the same problem. After adding this code, few images are being erased from media library.

        • WPBeginner Support says:

          Sudip, thank you for notifying us. We have updated the article. Please try the new code instead.

  23. UaMV says:

    One should also note that this deletes featured images not just from standard post, but from all posts (including custom post types), correct?

    • WPBeginner Support says:

      Yes this is correct. However, the query can be modify to exclude certain post types.

  24. James DiGioia says:

    Wouldn’t it be easier to just run a query on DB directly?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.