WordPress allows you to upload and display a variety of media file types like images, music, and videos. But when you delete the post, all of the files attached to that specific post are left orphaned in your media library causing an undeserved load on your website. Since these files are of no more use, you may use a plugin for automatically deleting such images.
Earlier, you have learned about deleting unattached images from your WordPress media library. Now in this lesson, you will learn about automatically deleting attached files when their post, page, or post type is removed.
How To Automatically Delete Image Attachments When Any Post Is Deleted In WordPress?
Autoremove Attachments plugin keeps your media library clean by removing all media files attached as attachments to a post, page, or custom post type when the parent post is deleted. Hence, you don’t have to manually track down and remove orphaned files that remain on the server.
To start using the plugin simply log in to your WordPress site and follow these steps:
- Navigate to Plugins -> Add New section
- Search and install the ‘Autoremove Attachments’ plugin
There are no configuration options to set. Upon activation, the plugin automatically starts working and it automatically removes child attachments when a parent post, page, or custom post type is deleted.
The Compatibility With Other Plugins
The ‘Autoremove Attachments’ plugin is compatible with WooCommerce i.e. WordPress Ecommerce plugin, Easy Digital Downloads plugin, and all plugins that work within the WordPress system.
Make Sure
That you are not using the same media files in multiple posts or you will end up missing images from other posts on your WordPress website. If you need to use the same images in addition to this plugin then you must re-upload such images for reusing them on other posts.
Another important thing you should know is files are deleted when the parent post, page, or custom post type is permanently deleted so a soft delete that moves the content to the trash does not trigger attachment deletion. Hence, in order to delete the attached media files, you will have to permanently delete the post from the trash bin.