Title: Autoremove Attachments
Author: Polygon Themes
Published: <strong>జూలై 10, 2015</strong>
Last modified: ఆగస్ట్ 12, 2023

---

Search plugins

![](https://ps.w.org/autoremove-attachments/assets/banner-772x250.png?rev=2348966)

This plugin **hasn’t been tested with the latest 3 major releases of WordPress**.
It may no longer be maintained or supported and may have compatibility issues when
used with more recent versions of WordPress.

![](https://ps.w.org/autoremove-attachments/assets/icon-256x256.png?rev=2348966)

# Autoremove Attachments

 By [Polygon Themes](https://profiles.wordpress.org/polygonthemes/)

[Download](https://downloads.wordpress.org/plugin/autoremove-attachments.zip)

 * [Details](https://te.wordpress.org/plugins/autoremove-attachments/#description)
 * [Reviews](https://te.wordpress.org/plugins/autoremove-attachments/#reviews)
 *  [Installation](https://te.wordpress.org/plugins/autoremove-attachments/#installation)
 * [Development](https://te.wordpress.org/plugins/autoremove-attachments/#developers)

 [Support](https://wordpress.org/support/plugin/autoremove-attachments/)

## Description

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)

### Important Considerations

 * A soft delete that places your post, page, or custom post type in Trash will 
   not trigger the removal of its child attachments. The purge happens when you 
   empty your trash.
 * When you delete a post, page or custom post type, we try to determine if its 
   child attachments are used anywhere else on your website. If they are, we do 
   not remove them, to prevent broken links.
 * The additional checks before the automatic removal can be disabled from the Media
   Settings for improved performance on large websites with thousands of posts and
   media files.
 * The plugin only removes files tracked by WordPress. Some poorly coded themes 
   generate additional thumbnail sizes that are not tracked by WordPress and this
   always leads to orphan files left on your server.

### Compatibility and Third-Party Support

 * [WooCommerce](https://wordpress.org/plugins/woocommerce)
 * [Easy Digital Downloads](https://wordpress.org/plugins/easy-digital-downloads)
 * All themes and plugins that do things the WordPress way

If you use a plugin to optimize and clean your database of revisions, trashed posts,
etc, make sure you use one that relies on native WordPress functions to perform 
the maintenance tasks. We recommend [WP-Sweep](https://wordpress.org/plugins/wp-sweep).

## Installation

### Automatic Installation

The automatic installation is the easiest option to install a plugin as WordPress
handles the file transfers itself. To do an automatic install, log in to your WordPress
dashboard and follow the steps below:

 1. Navigate to the Plugins menu and click “Add New”
 2. In the search field type “Autoremove Attachments” and click “Search Plugins”
 3. Once you have found the plugin install it by clicking “Install Now”
 4. Activate “Autoremove Attachments” from the “Plugins” menu

### Manual Installation

The manual installation method involves downloading the plugin and uploading it 
on your server via SFTP. To do a manual install follow the steps below:

 1. Download the plugin to your local computer
 2. If downloaded as a zip archive extract it to your Desktop
 3. Upload the plugin folder to the /wp-content/plugins/ directory
 4. Activate “Autoremove Attachments” from the “Plugins” menu

## FAQ

### Does it work with custom post types?

Yes, it does. It works with posts, pages and custom post types. All child attachments
are removed when the parent is deleted.

### When are the attachments removed?

The files are removed when the parent post, page, or custom post type is permanently
removed. A soft delete that places it in Trash will not trigger the removal of your
attachments.

The purge happens when you empty your trash.

### Can I control what attachments are removed?

Yes, you can. By default, all media files attached to a post, page or custom post
type are removed automatically. If you need granular control you can use the filter`
autoremove_attachments_allowed` to define custom rules for controlling when the 
child attachments should be removed automatically.

Here is an example on how you can remove the attachments only for specific custom
post types:

    ```
    function autoremove_attachments_custom_rule() {
        // Global variables.
        global $post_id;

        // Variables.
        $post_type          = get_post_type( $post_id );
        $allowed_post_types = array(
            'project',
            'product',
        );

        // Default return value.
        $allowed_to_remove = false;



        // Custom rules for removing attachments.
        if ( in_array( $post_type, $allowed_post_types ) ) {
            $allowed_to_remove = true;
        }



        // Return.
        return $allowed_to_remove;
    }
    add_filter( 'autoremove_attachments_allowed', 'autoremove_attachments_custom_rule' );
    ```

The returned value should be true for the cases in which you want the attachments
removed. (false otherwise)

### Are there any restrictions on how I can use my attachments?

Depending on how you use the plugin, the answer can be either yes, or no.

If you keep the plugin running with the additional checks enabled, you have no restrictions
on how you can use your attachments. (you can use your media files in multiple locations,
without the fear of broken links caused by their removal)

If you disable the additional checks, you need to make sure you don’t reuse your
media files between posts. If you do and the parent is deleted, you will end up 
with broken links in all the other locations where the removed attachments were 
used.

Regardless of how you use the plugin, if you need to use an attachment over and 
over again, upload it from the global Media Library menu. ( Media > Add New ) This
way, it won’t be attached as a child to a specific post, page, or custom post type
and you will be able to use it without restrictions.

## Reviews

![](https://secure.gravatar.com/avatar/fb31f647f8ab53a18cdca8f7c13b5329bba9c2ac5525279b17331d9a80e426b5?
s=60&d=retro&r=g)

### 󠀁[It autoremoves the attachments!](https://wordpress.org/support/topic/it-autoremoves-the-attachments/)󠁿

 [MaryMak](https://profiles.wordpress.org/maxms/) జనవరి 9, 2025

Simple, straightforward and does what it claims to do. Really useful and easy as
this task should be.

![](https://secure.gravatar.com/avatar/5b5180fb8b0568deed53b2a638f3575ef5e06bc82aa3a86b24bb48535052608e?
s=60&d=retro&r=g)

### 󠀁[Solved my use case!](https://wordpress.org/support/topic/solved-my-problem-65/)󠁿

 [jemcbade](https://profiles.wordpress.org/jemcbade/) సెప్టెంబర్ 26, 2021

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.

![](https://secure.gravatar.com/avatar/b05e6f39c8f7fedfd06a70c479350447aa8b5c95ce6df62325ff7b11e9c6e5ca?
s=60&d=retro&r=g)

### 󠀁[Simple and easy to use.](https://wordpress.org/support/topic/simple-and-easy-to-use-362/)󠁿

 [Weiching](https://profiles.wordpress.org/weiching-lin/) మే 14, 2021

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.

![](https://secure.gravatar.com/avatar/e308915395c38fd65e72310d4669824eb5ce361abeae326ac5b7010a2ffda6fb?
s=60&d=retro&r=g)

### 󠀁[Perfect](https://wordpress.org/support/topic/perfect-7056/)󠁿

 [doulou](https://profiles.wordpress.org/doulou/) ఏప్రిల్ 7, 2020 1 reply

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!

![](https://secure.gravatar.com/avatar/ec7ff96b9b925959c646c09743ff95ffc2ca772b6850cba45566b7cdc0256dab?
s=60&d=retro&r=g)

### 󠀁[Worked](https://wordpress.org/support/topic/worked-69/)󠁿

 [Mohsin Alam](https://profiles.wordpress.org/mohsinworld/) మార్చి 9, 2020 1 reply

This plugin worked when the image is featured image to the post, but can’t delete
which is uploaded in the middle of post.

![](https://secure.gravatar.com/avatar/329bb45f08785c2a516dee73ac02f4a578cfaebffa09048b85c088c673a6eab8?
s=60&d=retro&r=g)

### 󠀁[Saves tons of time & server resources](https://wordpress.org/support/topic/saves-tons-of-time-server-resources/)󠁿

 [wordmax](https://profiles.wordpress.org/wordmax/) డిసెంబర్ 11, 2019 1 reply

Had a blog with 3000 posts w/ images that I wanted to delete. I installed and activated
this plugin and then used Bulk Delete plugin to delete all 3000 old articles. This
plugin did a great job and there were no old images left in the uploads folder. 
Sooo much faster than doing this manually or using two separate plugins to get rid
of posts and then media. It took less than 1 minute to delete 3000 posts and the
attached media with the combo Bulk Delete/Autoremove Attachments plugins together.
Well done dev!

 [ Read all 15 reviews ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/)

## Contributors & Developers

“Autoremove Attachments” is open source software. The following people have contributed
to this plugin.

Contributors

 *   [ Polygon Themes ](https://profiles.wordpress.org/polygonthemes/)
 *   [ Eusebiu Oprinoiu ](https://profiles.wordpress.org/eusebiuoprinoiu/)

“Autoremove Attachments” has been translated into 1 locale. Thank you to [the translators](https://translate.wordpress.org/projects/wp-plugins/autoremove-attachments/contributors)
for their contributions.

[Translate “Autoremove Attachments” into your language.](https://translate.wordpress.org/projects/wp-plugins/autoremove-attachments)

### Interested in development?

[Browse the code](https://plugins.trac.wordpress.org/browser/autoremove-attachments/),
check out the [SVN repository](https://plugins.svn.wordpress.org/autoremove-attachments/),
or subscribe to the [development log](https://plugins.trac.wordpress.org/log/autoremove-attachments/)
by [RSS](https://plugins.trac.wordpress.org/log/autoremove-attachments/?limit=100&mode=stop_on_copy&format=rss).

## Changelog

#### Version 1.3.1

 * Minor improvements to admin notices

#### Version 1.3.0

 * Minor code refactoring
 * Language files updated

#### Version 1.2.1

 * Fixed a bug that blocked changes to image sizes under Settings > Media

#### Version 1.2.0

 * Minor code refactoring
 * Extended support for WooCommerce and Easy Digital Downloads.
 * New safety checks when you empty your trash – We now try to determine if the 
   child attachments marked for removal are used anywhere else on your website. 
   If they are, we do not remove them, to prevent broken links.
 * New option under Settings > Media to disable the extra checks for improved performance
   on large websites with thousands of posts and media files. (where you might experience
   slow queries and timeouts when you empty your trash)

**Other important considerations**

 * With the new safety checks enabled it’s fairly safe to reuse attachments between
   posts. But please, keep in mind, they are not fool-proof, especially if you store
   media file IDs or URLs in custom fields. That’s why we recommend you avoid reusing
   your attachments between posts, if possible.
 * If you need to use an attachment over and over again, upload it from the global
   Media Library menu ( Media > Add New ). This way, it won’t be attached as a child
   to a specific post, page, or custom post type.

#### Version 1.1.2

 * New filter added to allow developers define custom rules for controlling when
   the child attachments should be removed automatically
 * Removed the old ‘autoremove_attachments_post_types’ filter in favor of the new
   one – instructions available in FAQ

#### Version 1.1.1

 * New filter added to allow developers to change for what post types the child 
   attachments should be removed automatically ( see FAQ for instructions )
 * Fixed a minor incompatibility with WP-Sweep

#### Version 1.1.0

 * Minor improvements for the admin notice

#### Version 1.0.9

 * Performance improvements on websites with a large number of posts and attachments

#### Version 1.0.8

 * Added extra security checks before the removal of attachments
 * Added an admin notice with a warning about the limitations of this plugin and
   the consequences of its improper usage. ( for new users only )

#### Version 1.0.7

 * Minor code refactoring
 * Added full support for WordPress Multisite

#### Version 1.0.6

 * Code refactored using wpcs

#### Version 1.0.5

 * Improved the warning displayed when very old PHP versions are used

#### Version 1.0.4

 * Remove all options on uninstall, even for multisite

#### Version 1.0.3

 * Added a security check to avoid deleting attachments when the ID of the parent
   post is invalid

#### Version 1.0.2

 * Fixed a bug that was causing media files to be removed when revisions were deleted
   with wp-cron

#### Version 1.0.1

 * Minimum required version of PHP set to 5.3

#### Version 1.0.0

 * First release

## Meta

 *  Version **1.3.1**
 *  Last updated **3 సంవత్సరాలు ago**
 *  Active installations **3,000+**
 *  WordPress version ** 5.8 or higher **
 *  Tested up to **6.3.8**
 *  PHP version ** 7.4 or higher **
 *  Languages
 * [English (US)](https://wordpress.org/plugins/autoremove-attachments/) మరియు [Spanish (Spain)](https://es.wordpress.org/plugins/autoremove-attachments/).
 *  [Translate into your language](https://translate.wordpress.org/projects/wp-plugins/autoremove-attachments)
 * Tags
 * [attachment](https://te.wordpress.org/plugins/tags/attachment/)[custom post type](https://te.wordpress.org/plugins/tags/custom-post-type/)
   [media](https://te.wordpress.org/plugins/tags/media/)[page](https://te.wordpress.org/plugins/tags/page/)
   [post](https://te.wordpress.org/plugins/tags/post/)
 *  [Advanced View](https://te.wordpress.org/plugins/autoremove-attachments/advanced/)

## Ratings

 5 out of 5 stars.

 *  [  15 5-star reviews     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=5)
 *  [  0 4-star reviews     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=4)
 *  [  0 3-star reviews     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=3)
 *  [  0 2-star reviews     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=2)
 *  [  0 1-star reviews     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/autoremove-attachments/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/autoremove-attachments/reviews/)

## Contributors

 *   [ Polygon Themes ](https://profiles.wordpress.org/polygonthemes/)
 *   [ Eusebiu Oprinoiu ](https://profiles.wordpress.org/eusebiuoprinoiu/)

## Support

Got something to say? Need help?

 [View support forum](https://wordpress.org/support/plugin/autoremove-attachments/)

## Donate

Would you like to support the advancement of this plugin?

 [ Donate to this plugin ](https://paypal.me/EusebiuOprinoiu)