Whenever we delete any posts or pages on our WordPress its get deleted. But the featured images that you have attached to that posts or pages remain on your website.
And it can take space on your website server.
So the question is that:
Is there anything we can do to delete featured image when deleting post or page?
Yes, You just need simple code snippets that will do this work for you.
Here it is:
Remove featured image when deleting post
Just copy the below code snippets and paste in your WordPress theme’s functions.php file then save it.
Code Snippets for Delete Post with Image
How the Above code works?
When you delete the post or page, it goes to to trash and the featured image will still not delete…
…but when you delete that post from trash permanently, the image would also be deleted.
Hope the code is working fine for you without any error.
If you have any issues related to this post or WordPress, let us know in the comment box.
Don’t forget to share this Delete post or page with Featured Image guide.