WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There is a function in Wordpress that allows to display a "edit post" link if the user has sufficient rights.

<?php edit_post_link( __( 'Edit' ), '<small class="edit-link">', '</small>' ); ?>

Is there an equivalent for media files / attachments,

UPDATE This sorts of work

$images = fdw_get_post_images('preview-onepost-thumbnail');
if ($images){
  $counter= 0;
 foreach ($images as $image){
      $src = $image['src'];
      $info = $image['info'];
 edit_post_link( __( 'Edit image' ), '<section><small class="edit-link">', '</small></section>', $info->ID ); ?>

But the user actually need to be able to Delete the image. That screen does not allow it.

share|improve this question

This isn't 100% complete, but should be a good start for you.

<a href="<?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).
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.