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 manage attachment relationships for specific posts in WP 3.5+
- Change attachment filename
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- Expanding new Media Uploader in WordPress 3.5
- Applying automatic link class to images embedded to posts
- How to single click to download image in single post
- delete attachment from front end
- URL rewrite with add_rewrite_rule and attachment_id
- How to set author for post AND post attachments
- Add column for attachment file size
- how to test for attached image
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Making images from single.php pointing to an attachment .php template
- Add_Filter example for wp_get_attachment_link
- wp_get_attachment_image_src always returns false
- Exact image sizes
- Get the size (size in Kb or MB) of an featured image?
- Get attachment file link
- How to grab the first two image attachments from a post?
- wp_insert_post featured image from library
- Is it possible to modify the media library admin screen?
- the_content() behavior on attachment.php versus single.php
- Regenerate missing _wp_attachment_metadata
- Adding File Extensions to Attachment Page Permalinks
- Getting ID from ajax response of async-upload.php
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- Need clear explanation about medias/files/attchments
- post_author for wp_insert_attachment
- Get the bare URL for an attachment
- Audio file’s length (duration) is missing from Attachment Details in Media Library [closed]
- Attach media to multiple posts
- Don’t show attachments if they are inserted in post
- How do I modify the “Insert Media” lightbox in the admin to only show media items from a category?
- Media library quick/inline edit
- Email Attachment from Form Submit
- Check what attached image size is used
- Custom image sizes add to metadata
- How do you create an attachment ID with Ajax submit? No page refresh
- Get images attached to a specific page
- How to get $attachment->ID in custom functions
- All attachment pages give 404
- Unable to get wp_get_attachment_url to show
- Get Attachment Image Class by attachment id
- Automatically deactivate link for attachments
- After changing permalink structure, How to redirect attachment url to old parent post url
- Getting attachment post using wp_get_attachment_link
- wp_mail Allow Remote Attachments from CDN
- How can i set media attachments to the author of the post or page for already existed posts with attachments
- Custom field in media library not saving, selected() function not adding “selected” to select list input type
- Were attachment media settings removed from WordPress?
- How to identify and delete all the images/pdf’s which are not assigned to any post/custom-post/page and also which are repeated
- Filter not applied to all image sizes
- Zip a file and add as attachment
- What is wrong with my wp_insert_attachment code?
- Adding attachment custom field metadata to TinyMCE tag
- Remove post with attachments hook
- Setting an image as post header (not featured image)
- How to restrict users to only access their own media files in wordpress
- wp_mail doen’t send mails whit attachment
- When inserting attachments into a blog post, how can I get WordPress to use the full filename with the extension?
- List attachments of a page
- Importing Attachments with No Extension
- Post images not displaying as attachments
- Showing the attachment for a page?
- How can we select attachements based on Caption?
- Calling a javascript function in post edit page after attaching something to post
- Custom Fields, Media uploader, Attachments