Appearance
Delete Post Media
The Delete Post Media function automatically deletes all media attachments when a post is permanently deleted. This prevents orphaned media files from accumulating in your Media Library.
Overview
When posts are deleted in WordPress, their attached media files typically remain in the Media Library. Over time, this can lead to significant storage usage from orphaned files. This function automatically cleans up all associated media when a post is deleted.
Key Features
- Automatic media cleanup on post deletion
- Double confirmation dialog for safety
- Detects media from multiple sources (featured image, content, meta fields, Voxel fields)
- Configurable per post type
- Works with Voxel gallery, image, and file fields
Warning
This action is permanent. When you delete a post with this function enabled, all associated media files will be permanently deleted and cannot be recovered. Use with caution.
Setup Instructions
Step 1: Enable the Function
- Navigate to Voxel Toolkit → Functions in your WordPress admin
- Find Delete Post Media in the list
- Toggle the switch to enable the function
- Click Save Changes
Step 2: Select Post Types
Choose which post types should have automatic media deletion:
- In the Post Types section, check the boxes for the post types you want to enable
- Consider enabling for Voxel post types that have user-uploaded media (places, events, profiles)
- Click Save Changes
How It Works
Confirmation Dialog
When you click “Delete” on an enabled post type, a confirmation dialog appears warning you that:
- All attached media files will be permanently deleted
- This action cannot be undone
- You must check a confirmation checkbox to proceed
Media Detection Sources
The function finds media from multiple sources:
| Source | Description |
|---|---|
| Featured Image | Post thumbnail |
| Attached Media | Files with post as parent |
| Post Content | Images embedded in content |
| Post Meta | Media IDs stored in custom fields |
| Voxel Fields | Gallery, image, and file field types |
Use Cases
User-Generated Content Sites
For directory sites where users upload photos for their listings, automatically cleaning up media when listings are deleted prevents storage bloat.
Storage Management
Particularly useful on hosting plans with limited storage, keeping your Media Library clean and manageable.
Privacy Compliance
When users request account or listing deletion, this ensures their uploaded media is also removed.
Supported Media Detection
Detected File Types
- Images: JPG, JPEG, PNG, GIF, SVG
- Documents: PDF, DOC, DOCX
- Media: MP4, MP3
- Archives: ZIP
Voxel Field Types
- Image fields
- File fields
- Gallery fields
Troubleshooting
Confirmation Dialog Not Appearing
- Ensure jQuery UI Dialog is loading correctly
- Check browser console for JavaScript errors
- Clear browser cache
Media Not Being Deleted
- Verify the function is enabled for the post type
- Check that the media was actually attached to the post (not just used via URL)
- Some media may be used by multiple posts – shared media is not deleted
Accidentally Deleted Media
Unfortunately, deleted media cannot be recovered through WordPress. Consider:
- Restoring from a backup
- Checking if files exist on the server (may not be in Media Library)
- For future, always maintain regular backups

