How to Delete Featured Image When Deleting a Post

| Last Updated: | In: 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.

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.


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:


, , , , ,