Add a download image/video button to WordPress gallery

Product:

Wonder Gallery

Question:

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

Answer:

Step 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 with a class name wonderplugin_gallery_download_0:

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

Clicking the download button will download the image or the video that is currently displayed in the gallery.

Step 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_0").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);  
    }
    else
    {
      return false;
    }
  });
});

A demo is as follows. Clicking the download button will download the image or the video file that is currently displayed in the gallery.