How to Delete Featured Image When Deleting a Post

Prem Tiwari - - WordPress, WordPress Snippets

Are you a WordPress developer or running a WordPress website for your business, then keep your close attention in this post as I am going to explain how to delete featured image when deleting a post using wp_delete_attachment function.

Just assume if you are running a WordPress based blog and you have added some posts which contain images and after some time you deleted them, then your images are not deleted from your server and these all unused images and files are contains your server spaces and force your website to load slowly.

How to Delete Featured Image When Deleting Post

It is a better idea to remove the featured image during the post deletion time. In this, I will explain how to delete featured images using a WordPress hooks.

Copy the below code snippets and add it at the end of the functions.php file from you current activated theme.

Hope this tutorial help you, Do like and share this tutorial with your friends and also subscribe my blog to get my best tutorial directly in your email inbox. If you have any queries or suggestion regarding this tutorial, then feel free to put your comments in the below comment section.

Prem Tiwari

Prem Tiwari is the founder of and also a professional developer and a blogger by hobby.

Tags: , , , , ,

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.