Title: [Plugin: NextGEN Gallery] Adding a download link/button
Last modified: August 20, 2016

---

# [Plugin: NextGEN Gallery] Adding a download link/button

 *  Resolved [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/)
 * I have figured out how to add an automatic download link on an imagebrowser page
   by linking to force-download.php but I am not sure how to reference the file 
   location in the gallery view since the image links to the imagebrowser page, 
   not to the image itself.
 * Is there a variable that works in the gallery page when using imagebrowser that
   would give me the path to each image? Thanks!
 * See example here:
    Does not work (Bajar means download): [http://tesorodigital.mysitecreations.com/contenido/galeria/508-cartas-graficas/](http://tesorodigital.mysitecreations.com/contenido/galeria/508-cartas-graficas/)
   Works: [http://tesorodigital.mysitecreations.com/contenido/galeria/508-cartas-graficas/?pid=1](http://tesorodigital.mysitecreations.com/contenido/galeria/508-cartas-graficas/?pid=1)
 * [http://wordpress.org/extend/plugins/nextgen-gallery/](http://wordpress.org/extend/plugins/nextgen-gallery/)

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105165)
 * I tried $image->href and this almost works, but it adds in the whole thumbnail
   and everything, and I just want a link to the picture.
 * In another post I see referenced a method to access the database
 * `<?php $album = nggdb::find_album( get_query_var('album') ); ?>`
 * Does anyone know the function like this to get the proper data for the current
   image href?
 * Thank you.
 *  [Trew Knowledge](https://wordpress.org/support/users/trewknowledge/)
 * (@trewknowledge)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105187)
 * I am also looking to have the ability to have a download button on the Gallery
   page.
 * I have tried a couple of things but have had no luck.
 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105188)
 * If I don’t use imagebrowser I think I got it to work on the gallery page, but
   with imagebrowser I can’t get it yet. Oh well, at least I have it on imagebrowser
   for now.
 *  [Trew Knowledge](https://wordpress.org/support/users/trewknowledge/)
 * (@trewknowledge)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105189)
 * Can you please explain how you got it to work without using imagebrowser.
 * Is it something that comes with NextGen gallery? or is this something that you
   created?
 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105196)
 * It involves adding some code to /wp-content/plugins/nextgen-gallery/view/gallery-
   caption.php (or you probably want to make your own custom theme by copying the.
   php file and naming it gallery-mytemplate.php and referencing [template=mytemplate]
 * Here’s a snippet from my gallery-template file that includes modified code:
    _[
   Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * Then you need to upload force-download.php to your home directory.
    Code for 
   this file is as follows:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * You’ll probably have to tweak the code to your liking. Instead of the hyperlink
   you can make it a button.
 * I think this would work. You may have to adjust other settings in the gallery.
   I think you have to use the caption template, can’t remember for sure. See if
   it works and let me know.
 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105198)
 * Sorry, I edited the code above slightly. The important line is
 *     ```
       <!-- ADD DOWNLOAD LINK, changed image-caption to image-alttext NB ???  -->
       <span><?php echo $image->alttext ?><br /><?php echo $image->caption; ?><br /><a href=" <?php home_url(); ?> /force-download.php?file=<?php echo substr(parse_url($image->imageURL,PHP_URL_PATH),2); ?> ">Download</a></span>
       ```
   
 * I tested without imagebrowser and it works on my settings.
 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105207)
 * Another note: the “2” in the following code may need to be “1” depending on how
   the location of the gallery images is entered in the gallery configuration page.
   If it begins with a “/” you’ll need a 2 to eliminate it, if it begins with a 
   folder name, you need a 1.
    `substr(parse_url($image->imageURL,PHP_URL_PATH),
   2);`
 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [15 years ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105284)
 * UPDATE: I decided to forget about imagebrowser and just use the shutter style,
   so the links in the first post no longer demonstrate the problem.
 *  [davejworth](https://wordpress.org/support/users/davejworth/)
 * (@davejworth)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105431)
 * Hi nbruley – I’ve been searching and searching for a solution like the one you
   are describing. Could you re-post the PHP that has been moderated out?
 * Many thanks!
 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105432)
 * Force download code (images/audio):
    [http://pastebin.com/c7RxpsPP](http://pastebin.com/c7RxpsPP)
 * my NextGEN template file (complete)
    [http://pastebin.com/Z709fu0f](http://pastebin.com/Z709fu0f)
 * Hope that helps.
 *  [The Gal](https://wordpress.org/support/users/peterpevensie/)
 * (@peterpevensie)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105436)
 * Sir, you are a genius. I just used your code as well and it worked so well, I
   quite literally exclaimed aloud with joy. 😀 THANK YOU for sharing your work!!!
 *  [davejworth](https://wordpress.org/support/users/davejworth/)
 * (@davejworth)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105437)
 * nbruley – fantastic! Worked like a dream.
 * Many thanks.
 *  [ernaparalla](https://wordpress.org/support/users/ernaparalla/)
 * (@ernaparalla)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105438)
 * This looks like what I’m trying to do butI’m not using either of these galleries.
   I have a single image in each of my WP posts and want to add a link within the
   post (located in on single.php file) to download that image (ideally, I’ll configure
   it to display 3 links to allow users to download a large, medium, or small image).
 * Is this possible with what you have here?
    Thanks!
 *  Thread Starter [nbruley](https://wordpress.org/support/users/nbruley/)
 * (@nbruley)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105439)
 * ernaparalla, yes, this should work. If I understand you correctly, you would 
   use only the force-download.php file and create a link to download a specific
   file using a URL like
    mySite.com/force-download.php?file=small/myFile.jpg mySite.
   com/force-download.php?file=medium/myFile.jpg mySite.com/force-download.php?file
   =large/myFile.jpg
 * In your case, you may wish to put the different sized images in different folders
   and call them by the same file name. This might simplify the php coding.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘[Plugin: NextGEN Gallery] Adding a download link/button’ is closed to
new replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

 * 14 replies
 * 5 participants
 * Last reply from: [nbruley](https://wordpress.org/support/users/nbruley/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-download-linkbutton/#post-2105439)
 * Status: resolved