Bulk Remove Featured Images
Adds a "Remove featured image" bulk action to post and page lists that clears the featured image from all selected items at once, without deleting the images from the Media Library.
Opens WPIDE on
Code
foreach ( array( 'post', 'page' ) as $wpide_type ) {
add_filter( "bulk_actions-edit-{$wpide_type}", function ( $actions ) {
$actions['wpide_remove_thumbnail'] = 'Remove featured image';
return $actions;
} );
add_filter( "handle_bulk_actions-edit-{$wpide_type}", function ( $redirect, $action, $post_ids ) {
if ( 'wpide_remove_thumbnail' !== $action ) {
return $redirect;
}
$done = 0;
foreach ( $post_ids as $post_id ) {
if ( current_user_can( 'edit_post', $post_id ) && delete_post_thumbnail( $post_id ) ) {
$done++;
}
}
return add_query_arg( 'wpide_thumbs_removed', $done, $redirect );
}, 10, 3 );
}
add_action( 'admin_notices', function () {
if ( isset( $_GET['wpide_thumbs_removed'] ) ) {
printf( '<div class="notice notice-success is-dismissible"><p>Removed the featured image from %d items.</p></div>', absint( $_GET['wpide_thumbs_removed'] ) );
}
} );
Notes
The images stay in the Media Library and can be set again at any time.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.