Add a download image/video button to WordPress gallery


WonderPlugin Gallery


I need my users to be able to download any of the self hosted video and image files. Is this possible?


1. In the WordPress post or page, where you have added the gallery shortcode, switch to "Text" edit mode, add the following code to create a button link with a class name wonderplugin_gallery_download:

<a href="#" class="wonderplugin_gallery_download"><button>Download</button></a>

2. In the plugin, step 3 Options tab, Advanced Options, add the following code to the Custom JavaScript input box:

jQuery(document).ready(function() {
  jQuery(".wonderplugin_gallery_download").click(function() {
    var cur = html5GalleryObjects.objects[0].curElem;
    var curElem = html5GalleryObjects.objects[0].elemArray[cur];
    var downloadlink = (curElem[9] == 1 || curElem[9] == 6) ? curElem[2] : "";
    if (downloadlink)
      var filename = downloadlink.substring(downloadlink.lastIndexOf('/') + 1);
      jQuery(this).attr("href", downloadlink);  
      jQuery(this).attr("download", filename);  
      return false;

A demo is as follows: