Delete WordPress Attachments when Deleting Post

I was trying to find a way to delete the media files attached to all WordPress posts when deleting a bunch of posts at once. I did not want to leave behind a bunch of media files once I got rid of the posts. Turns out there is a way to do this but you have to add some code to your functions.php file. Below is the code to add to functions.php. Be sure to delete this when you are done.

This snippet was found here: http://www.loneshooter.com/wordpress-deleting-images-when-deleting-post/

This Post Has One Comment

  1. It’s not working with wp 4.7.5.

Leave a Reply

Close Menu