WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How To Bulk Remove Featured Images From Posts in WordPress

How To Bulk Remove Featured Images From Posts in WordPress

Last updated on December 21st, 2013 by Editorial Staff
46 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
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

46 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

41 Comments

Leave a Reply
  1. Gregh777 says:
    Jul 28, 2019 at 10:50 am

    This little line of code saved me a lot of hassle. Thanks for that! I had imported about 50 articles and WordPress was saying each one had a featured image when it did not have one.

    I already know why it was doing that…long story…however, how am I to remove the featured image when there is nothing to remove?? Just paste these lines of code into the functions.php file like the article says and voila! All ghost images removed :D

    wpbeginner makes me SO happy ;)

    Reply
    • WPBeginner Support says:
      Jul 29, 2019 at 12:05 pm

      Glad our article could help :)

      Reply
  2. Asfianda says:
    Jul 11, 2019 at 2:00 am

    Thanks, this so helpfull for me.

    Reply
    • WPBeginner Support says:
      Jul 11, 2019 at 12:51 pm

      You’re welcome, glad our content could be helpful :)

      Reply
  3. David says:
    Mar 22, 2018 at 1:22 pm

    Thank you.

    Reply
  4. hercules says:
    Apr 26, 2017 at 3:01 am

    Deleting all the server images assigned to the thumbnails is relatively simple, now, how to condition to delete all uploads not used by the server as featured images? This should be the most interesting, clean the images not used by the system, in order to polish the machine resources deleting junk images, not used.

    Reply
  5. Peter says:
    Apr 21, 2017 at 10:19 am

    Yes! So helpful, thank you!!!

    Reply
  6. aman says:
    Apr 18, 2017 at 12:04 pm

    it works thank you , but what if i want to remove the post that don’t have feature image , how can i do that ?

    Reply
  7. Imbert says:
    Mar 1, 2017 at 6:04 am

    Thanks a lot, you really rocks guys!!!

    Reply
  8. lszllvnt says:
    Nov 2, 2016 at 12:48 pm

    it works ! just don’t use with child theme.

    Reply
  9. Em says:
    Oct 23, 2016 at 9:31 am

    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.

    Reply
  10. Dan says:
    May 25, 2016 at 3:38 am

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

    Reply
  11. Jax says:
    Mar 31, 2016 at 3:10 pm

    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

    Reply
  12. Mike says:
    Mar 22, 2016 at 10:23 am

    #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,
    Mike

    Reply
  13. RaviTeja Adibhatla says:
    Mar 15, 2016 at 12:54 pm

    Works like charm. Thanks man :)

    Reply
  14. Afzal says:
    Feb 25, 2016 at 7:02 pm

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

    Reply
  15. srijita chattopadhyay says:
    Feb 9, 2016 at 5:52 pm

    THANK YOU!

    Reply
  16. Raakib Hasan says:
    Aug 19, 2015 at 11:33 am

    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?

    Reply
  17. Luke Melbourne says:
    May 15, 2015 at 8:44 pm

    Awesome! Just what I needed. Thank you.

    Reply
  18. Karen says:
    May 7, 2015 at 6:05 pm

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

    Reply
  19. Zaid Sparrow says:
    Apr 18, 2015 at 7:24 am

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

    Reply
  20. Abdul says:
    Jul 10, 2014 at 2:17 pm

    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 happened.how do i stop featured images to be shown on blog page?Thanks

    Reply
  21. Irmina Santaika says:
    Jun 5, 2014 at 2:21 pm

    Thank you so much!

    Reply
  22. Abhishek Mishra says:
    May 25, 2014 at 9:09 am

    Sorry dude, its now working

    Reply
  23. w0ngsimp4ng says:
    May 7, 2014 at 4:13 pm

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

    Reply
  24. Jeff says:
    Apr 2, 2014 at 2:00 pm

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

    thanks,
    Jeff

    Reply
  25. Marcelo says:
    Mar 14, 2014 at 8:46 pm

    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?

    Reply
  26. Robin Solanki says:
    Mar 6, 2014 at 8:05 am

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

    Reply
  27. Rahul says:
    Feb 12, 2014 at 1:46 pm

    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.

    Reply
    • WPBeginner Support says:
      Feb 12, 2014 at 5:01 pm

      You will have to delete images from media library.

      Reply
      • Rahul says:
        Feb 16, 2014 at 10:23 am

        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

        Reply
  28. Nicholas says:
    Jan 9, 2014 at 12:35 pm

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

    Reply
  29. Biriisi says:
    Dec 13, 2013 at 2:14 pm

    Thanks man!!

    Reply
  30. Justin Edwards says:
    Nov 17, 2013 at 7:36 pm

    BEWARE

    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.

    Reply
    • WPBeginner Support says:
      Nov 18, 2013 at 5:40 am

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

      Reply
      • Sudip says:
        Dec 21, 2013 at 11:52 am

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

        Reply
        • WPBeginner Support says:
          Dec 21, 2013 at 2:37 pm

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

  31. UaMV says:
    Oct 26, 2013 at 2:27 pm

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

    Reply
    • WPBeginner Support says:
      Oct 27, 2013 at 1:08 pm

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

      Reply
  32. James DiGioia says:
    Oct 24, 2013 at 12:12 pm

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

    Reply
    • WPBeginner Support says:
      Oct 24, 2013 at 12:40 pm

      Yep, and this is exactly what this code is doing.

      Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
SeedProd Logo
SeedProd
Create beautiful custom landing pages - Drag & drop builder. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2021 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2021)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2021)
    • SiteGround Reviews from 4464 Users & Our Experts (2021)
    • Bluehost Review from Real Users + Performance Stats (2021)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2021 – Step by Step Guide
Deals & Coupons (view all)
Shop Plugins
Shop Plugins Coupon
Get 15% OFF on Shop Plugins WordPress WooCommerce plugins.
Rocket coupon code
Rocket Coupon
Get 50% OFF on Rocket managed WordPress hosting plans for 3 months.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
  • Growth Fund
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon
  • AIOSEO

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress Security by Sucuri.