...

How To Bulk Remove Featured Images From Posts in WordPress

112

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

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.