Family Encyclopedia >> Electronics

How to bulk remove featured images from WordPress posts

Recently, one of our readers asked us how they can bulk remove featured images from WordPress posts. At WPBeginner, we have discussed featured images (post thumbnails) many times. We show you how to add featured images in WordPress, how to add new image sizes in WordPress, how to regenerate thumbnails, we even show 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, deleting them one by one can be time consuming. Instead, we are going to try a different approach. We'll run a database query and unset the featured images on all posts.

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

All you need to do is copy and paste this code into your theme funciones.php proceedings.

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

That is all. As soon as you save the functions.php file, this script will execute a database query and remove featured images from all posts.

Important: Delete this code immediately after saving the 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 saved you time and enabled you to bulk remove featured images from WordPress posts. For questions and comments please leave a comment below.

Source:Kaiser