Is there a way have a download link so that users can directly download uploaded images on a wordpress theme?

I have seen this guide for something like this http://fcontheweb.com/articles/force_download/ but it is not wordpress specific and was not able to get it to work

Is there something easier to implement?

Currently i am able to link directly to the image and users are able to view the image in the browser but i want users to be able to download instead.


  • Yes, that is what you'll have to do: set a Content-Disposition: attachment header, which means create a new endpoint to make the request to which will add the header and stream the file, like your example code. I haven't done this for WordPress but at first glance it looks like you could use admin_ajax or maybe the REST API
    – Rup
    Mar 12 '19 at 10:32
  • hmm dont know how to do that? is it too complicated to do as an answer i can follow?
    – uberrebu
    Mar 12 '19 at 14:45
  • I haven't tried it either, sorry. I don't know anything more than the pages I linked to.
    – Rup
    Mar 12 '19 at 14:57

You should just be able to use the HTML5 download attribute for that. So just make your links look like this:

<a href="<?php echo wp_get_attachment_image_url($id); ?>" download>Download Image</a>

where $id is the attachment ID

  • wow..you are the man!!!..worked like a champ
    – uberrebu
    Mar 12 '19 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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