This isn’t 100% complete, but should be a good start for you.
<a href="https://wordpress.stackexchange.com/questions/31371/<?php echo wp_nonce_url("/wp-admin/post.php?action=delete&post=$post->ID", 'delete-attachment_' . $post->ID ) ?>"><?php _e( 'Delete Permanently' ) ?></a>
A couple notes on what you’ll have left to do:
- This will do no confirmation, so you’ll probably want to use JS to verify that it wasn’t clicked by mistake
- This will redirect back to the current page, which will no longer exist. The URI may look something like,
?attachment_id=704&deleted=1
. You’ll want to intercept front-end attachment requests where$_GET['deleted'] == '1'
and handle that gracefully (e.g. redirect).
Related Posts:
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- How can I bulk delete media and attachments using WP-CLI?
- complex restriction of items in media library
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Unattaching unlinked images
- Show Post ID in “Find Posts or Pages” box in Media Library?
- 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
- Perform a custom (bulk) action in media view
- How to retrieve alt attribute for an attachment (uploaded image)?
- Where does the gallery shortcode gets its attachments from?
- Control attachments menu order with jQuery Sortable
- Is it possible to share media files between multiple WordPress sites?
- Open the Attachment Details popup
- Proper use of wp_get_attachment_image?
- how to get random media id from media gallery
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- Get an image from the media library. Struggling with the code?
- Media Library Mess After FTP … /uploads
- Media item permalink goes to source file instead of attachment.php
- wp_get_attachment_image_src calling wrong location
- Removing images deleted from uploads folder, from Media Library
- 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?
- 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
- Bulk delete media by year
- Media library upload hook
- How To Retrieve An Image Attachment’s Alt Text?
- How to Fix HTTP Error When Uploading Images?
- How to manage attachment relationships for specific posts in WP 3.5+
- Programmatically adding images to media library
- Can I add a Category Metabox to attachment?
- Change attachment filename
- How to get attachment file name not attachment URL
- How to trigger a refresh in the media modal
- Custom collection in media manager?
- Delete Associated Media Upon Page Deletion
- Get all post attachments except featured image
- getting attachement images src and add classes
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- How to cleanly delete attachment but retain original file?
- Changing attachment urls?
- Add custom class to attachment in media library grid mode
- Are captions stored anywhere?
- Trying to hide buttons from Attachment window
- get_the_post_thumbnail() doesn’t taking style attribute
- Expanding new Media Uploader in WordPress 3.5
- How can I UN-attach media from a post?
- Uploading Multiple Attachments From Front-End With A Description
- Validate alt text for attachments?
- Remove duplicate attachments
- How could I add button next to “edit image” button in “Attachment Details”
- Applying automatic link class to images embedded to posts
- How to get attachment caption (get_the_excerpt gives parent post excerpt) ?
- Is it possible to query specific WordPress Attachment files (.ppt & .pdf) and output them in a list?
- Detect if is image unattached
- Password protect some uploaded files, so only logged-in users can view them
- How to single click to download image in single post
- delete attachment from front end
- How to get attachments for a specific post type?
- Give attachments an archive page
- How can I hide media library images from general users?
- custom fields for attachments?
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- URL rewrite with add_rewrite_rule and attachment_id
- Saving Custom Field in Attachment Window in WordPress 3.5
- How to add media from front-end to an existing post?
- How to set author for post AND post attachments
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- Retrieving a custom link on an attachment
- Get attachment from post
- How can I display custom fields value from attachment media?
- Delete attachments from Front end
- Add column for attachment file size
- Creating a multi-file upload form on the front end for attachments
- how to test for attached image
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Get attachments (get_posts) and WP 3.5 new uploader
- get post attachments of a particular size
- Change image link: wp_get_attachment_link
- Multi-line captions on attachments
- Make individual attachments private?
- exposing attachment uploading to the front end — delicate
- Making images from single.php pointing to an attachment .php template
- Add_Filter example for wp_get_attachment_link
- Change the Permalink for wordpress attachment
- How to upload image from front end and save in media library?
- ID of images from gallery
- How to get list of paths (not urls) for an image
- How to save custom fields for attachments
- wp_get_attachment_image_src always returns false
- Exact image sizes
- Get post embedded image caption