Remove child attachments when parent post, page or custom post type is deleted.
As of April 2026, Autoremove Attachments is a WordPress page plugin with 3.0K+ active installations and a 5/5 rating from 15 reviews. It has been downloaded 34K+ times in total. Requires WordPress 5.8+ and PHP 7.4+. Available on WordPress.org since 2015. Last updated 2 years ago — may have compatibility concerns. Downloads are down 6% this week. Top alternative: Post Type Switcher.
Autoremove Attachments helps you keep the Media Library clean by deleting all media files attached as child attachments to a post, page, or custom post type when the parent is deleted.
By default, when you delete content from your website, regardless if it’s a post, a page, a product, or any kind of post type, WordPress keeps the media files previously associated with it, even if after the removal of your content they are not used anywhere else.
Autoremove Attachments tries to solve this problem by automating the removal of all media files that have a child-parent relationship with the removed content. (so you don’t have to manually track and remove orphan files left on your server)
Simple, straightforward and does what it claims to do. Really useful and easy as this task should be.
I have clients that create attachments for a CPT, delete the post but leave the Media in the library. “Why is my site getting so big? The backups are HUGE now!” *facepalm*
Thank you for the code for the filter to only effect certain post types so they don’t break the site 😛
Very well thought out use case and code. So far works with WP 5.8.1 and Metabox CPTs.
I provide the user front-end to publish articles, and I need to delete them frequently, which saves me a lot of time.
Thank you.
I wish I’d discovered this plugin a while back! My client has a website with 2 custom post types and constant posts being added and removed. The plugin works perfectly (I was worried about the galleries). Thanks for a great time-saving plugin!
This plugin worked when the image is featured image to the post, but can’t delete which is uploaded in the middle of post.
| WordPress | 5.8+ requiredTested up to 6.3.8 |
| PHP | 7.4+ required |
Plugin data sourced from WordPress.org. Analysis and metrics by PluginSift.