Edit image / Delete image link

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&amp;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).

Leave a Comment