Skip to content

How To Bulk Remove Featured Images From WordPress Posts

If you’re changing your WordPress’ theme or niche to a non-featured image one, or doing something similar to this, then you might wanna remove featured images from WordPress posts.

It’s impossible for blogs with tons of post to remove the featured images from all posts at once, but WPBeginner has a great snippet to remove all featured images at once. This snippet will only remove the featured images from the posts, but the image will not be deleted from your site.

Add following snippet to your theme’s functions.php file:

global $wpdb;

$attachments = $wpdb->get_results( "
     SELECT *
     FROM $wpdb->postmeta
     WHERE meta_key = '_thumbnail_id'
" );

foreach ( $attachments as $attachment ) {
    wp_delete_attachment( $attachment->meta_value, true );
}

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

[alert style=”red”]Note: Please remove this code immediately after saving your functions.php file. You only need to run this code once, there’s no need to keep this code in your theme.[/alert]

Leave a Reply

Your email address will not be published. Required fields are marked *