wordpress sucks in keeping media<=>content relationships. Part of the problem is that by default all media are public once they are uploaded and you have no way to know where are they are being used. Just because an image is not referenced anymore in its original post doesn’t mean that it is not referenced at any other place (sidebar widget?) or maybe by some external site, therefor deleting an image just because it is unattached is a very dangerous idea that can lead to a very big fail situation.
For what you want I think it is better to use the actual server access log than the content. Get a process running that once a month goes over all the images and find those that didn’t have any hits, and go and delete them.
Related Posts:
- How can I bulk delete media and attachments using WP-CLI?
- Get all posts (of any post type) an attachment is used in
- How to retrieve alt attribute for an attachment (uploaded image)?
- Media Library Mess After FTP … /uploads
- How to Fix HTTP Error When Uploading Images?
- How to manage attachment relationships for specific posts in WP 3.5+
- How to trigger a refresh in the media modal
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- Expanding new Media Uploader in WordPress 3.5
- Uploading Multiple Attachments From Front-End With A Description
- complex restriction of items in media library
- Edit image / Delete image link
- media_sideload_image file name?
- Password protect some uploaded files, so only logged-in users can view them
- How to single click to download image in single post
- Show Post ID in “Find Posts or Pages” box in Media Library?
- Delete attachments from Front end
- Get attachments (get_posts) and WP 3.5 new uploader
- Gel all image from certain post type
- Can i hide the attachments from media which I uploaded from front end?
- Get the attachment URL on single.php
- How to count media attachments?
- Get url from file uploaded in Media Library
- Perform a custom (bulk) action in media view
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- Get the path of the first attached media (single.php)
- Show attached media image if no thumbnail image detected
- How to fetch only media that was already attached to a post/page?
- Audio file’s length (duration) is missing from Attachment Details in Media Library [closed]
- Post edit – Media Library – Only get images from current post
- Attach media to multiple posts
- Where does the gallery shortcode gets its attachments from?
- media ‘path’ issue / concern when bringing files live
- Control attachments menu order with jQuery Sortable
- How do I modify the “Insert Media” lightbox in the admin to only show media items from a category?
- Media library quick/inline edit
- Is it possible to share media files between multiple WordPress sites?
- Open the Attachment Details popup
- How to compress image before inserting to wordpress using wp_insert_attachment function?
- Massive photogallery import
- Proper use of wp_get_attachment_image?
- how to get random media id from media gallery
- Get images attached to a specific page
- the_time() returning wrong date/time (way in the future)
- Gutenberg Block: Image resolution
- WordPress Attachments with old images
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- Get an image from the media library. Struggling with the code?
- get all images from the wordpress media library with link to the post they are associated with
- How can i set media attachments to the author of the post or page for already existed posts with attachments
- Media item permalink goes to source file instead of attachment.php
- Adding attachment custom field metadata to TinyMCE tag
- wp_get_attachment_image_src calling wrong location
- wp_delete_attachment doesn’t delete image files / doesn’t work
- Removing images deleted from uploads folder, from Media Library
- Setting an image as post header (not featured image)
- Using the GetMediaLibrary() method in python-wordpress-xmlrpc.media, how to iterate over the result?
- WP media attachment location vs permalink
- Removing delete permanently button in uploading files media
- Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?
- controlling whether upload is attached to post or not
- Remove attached media
- Is there a way to add Reattach and Unattach links in image gallery?
- How to retrieve images contained in a post
- How to save media-form on custom tab
- Media library only show 2 items per page?
- Bulk delete media by year
- Media library upload hook
- How to show all available images in WP’s media library when using the Polylang plugin?
- Changing attachment urls?
- Add custom class to attachment in media library grid mode
- How to extend LINK TO functionality in ATTACHMENT DISPLAY SETTINGS
- Best plugin to manage media library? [closed]
- How to add media from front-end to an existing post?
- exposing attachment uploading to the front end — delicate
- How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page
- Upload images from custom plugin using the media modal
- WordPress 3.5 Media Manager – add a button
- Link to full size image or attachment page in photo theme
- How to get media objects
- Duplicate Custom Header Functionality into the post edit screen
- My Media Library is broken across all my subsites
- How to select multiple media files for a widget form?
- How to get the return value of wp.media({ frame: ‘post’ }) in all cases?
- Post Gallery list attachments except the one used as post thumbnail
- Echo Permalink in Attachment outside of loop?
- Remove attachment from database
- Do custom post type (CPT) attachments/media store the parent post ID?
- Programmatically Altering Gallery Link and image size?
- Post images are not displayed in media library
- File was uploaded, but it is not shown on media section of the dashboard
- How to make the media library searchable by image title
- Restricted Attachments/Change Attachment Upload Location
- Hide Image Container if No Image Attachments
- How to get only current images of a post
- WordPress Attachments vs Post Meta
- open image after clicking on single.php with different stylesheet in wordpress
- How do I get link URL (not file URL or attachment URL) of an attached image [duplicate]
- add_image_size is not generatin images of correct dimensions
- Change the next thumbnail to text