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 / 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.
thanks
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/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.
thanks
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
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 Commented Mar 12, 2019 at 10:32