banner



Download How to Remove Featured Image When Deleting a Post FREE

How to Off Featured Image When Deleting a Post with wp_delete_attachment

Snippets by IsItWP

Are you looking for a way to remove featured image when deleting a post with wp_delete_attachment? While on that point's probably a plugin for this, we have created a quick code snippet that you give the axe use to remove featured persona when deleting a post in WordPress.

When you delete a post or page, the featured image that you've attached to it will remain there on your website. If you want to remove the featured image attachments as wellspring while deleting the postal service or foliate, then go on in mind:

  • If the Lapplander featured image is attached to multiple posts, then permanently deleting any of those posts testament delete the featured image also.
  • The images will only be removed when you permanently cancel the post from chalk.

Instructions:

All you have to practise is contribute this code to your theme's functions.php file or in a site-specific plugin:

add_action( 'before_delete_post', 'wps_remove_attachment_with_post', 10 ); function wps_remove_attachment_with_post($post_id) {  	if(has_post_thumbnail( $post_id ))         { 	  $attachment_id = get_post_thumbnail_id( $post_id ); 	  wp_delete_attachment($attachment_id, true); 	}  }          

Note: If this is your first metre adding code snippets in WordPress, then please refer to our guide on how to right tot up write in code snippets in WordPress, so you assume't accidentally break your site.

If you liked this code snippet, delight consider checking out our other articles on the site like: 7 best WordPress GDPR plugins to create a GDPR conformable website and how to create a WordPress contribution configuration.

Download How to Remove Featured Image When Deleting a Post FREE

0 Response to "Download How to Remove Featured Image When Deleting a Post FREE"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel