Title: [Plugin: NextGEN Custom Fields] Code for Gallery Field is Wrong
Last modified: August 20, 2016

---

# [Plugin: NextGEN Custom Fields] Code for Gallery Field is Wrong

 *  Resolved [Chris](https://wordpress.org/support/users/lamordnt/)
 * (@lamordnt)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/)
 * I am not sure if this is a one off but the code the developer shows under the“
   FAQ” area for the Gallery field is wrong.
 * The developer says to use: `<?php echo nggcf_get_gallery_field($gallery->ID, "
   My Gallery Field Name Here"); ?>`
 * However, this does not work. What does work is this:
    `<?php echo nggcf_get_gallery_field(
   $gallery->gid, "My Gallery Field Name Here"); ?>`
 * So you need to change the “ID” to “gid”.
 * Hope that helps someone, took me awhile to figure out.
 * [http://wordpress.org/extend/plugins/nextgen-gallery-custom-fields/](http://wordpress.org/extend/plugins/nextgen-gallery-custom-fields/)

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

 *  Plugin Author [shauno](https://wordpress.org/support/users/shauno/)
 * (@shauno)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/#post-2868100)
 * Thanks for the heads up Chris. I will get the info updated when I get the chance
   🙂
 *  [kkri](https://wordpress.org/support/users/kkri/)
 * (@kkri)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/#post-2868392)
 * _[ Moderator Note: Please post code or markup snippets between backticks or use
   the code button. Or better still – use the [pastebin](http://wordpress.pastebin.com/)]_
 * I used the plugin to create a gallery with links pointing to an external page.
 * [http://www.ilmetauro.it/sfogliagiornale](http://www.ilmetauro.it/sfogliagiornale)
 * I had to insert some code to choose to see simply an image (if it has no custom
   fields) or to link to the page (if link is present in each image of the gallery.
   It worked fine, but today I have upgraded NGGallery to the last version, my code
   has been overwritten by the new gallery.php and now I tried so many times to 
   add my code again, but I see a normal image, but my gallery images don’t point
   to external links anymore. Is there something going wrong with last NGG pllugin?
   How to add my code in gallery.php? This is my code:
 *     ```
       <?php 
   
       /**
   
       Template Page for the gallery overview
   
       Follow variables are useable :
   
       	$gallery     : Contain all about the gallery
   
       	$images      : Contain all images, path, title
   
       	$pagination  : Contain the pagination content
   
        You can check the content when you insert the tag <?php var_dump($variable) ?>
   
        If you would like to show the timestamp of the image ,you can use <?php echo $exif['created_timestamp'] ?>
   
       **/
   
       ?>
   
       <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?><?php if (!empty ($gallery)) : ?>
   
       <div class="ngg-galleryoverview" id="<?php echo $gallery->anchor ?>">
   
       <?php if ($gallery->show_slideshow) { ?>
   
       	<!-- Slideshow link -->
   
       	<div class="slideshowlink">
   
       		</a><a>slideshow_link ?>">
   
       			<?php echo $gallery->slideshow_link_text ?>
   
       		</a>
   
       	</div>
   
       <?php } ?>
   
       <?php if ($gallery->show_piclens) { ?>
   
       	<!-- Piclense link -->
   
       	<div class="piclenselink">
   
       		<a>piclens_link ?>">
   
       			<?php _e('[View with PicLens]','nggallery'); ?>
   
       		</a>
   
       	</div>
   
       <?php } ?>
   
       	<!-- Thumbnails -->
   
       	<?php foreach ( $images as $image ) : ?>
   
       	<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box" <?php echo $image->style ?> >
   
       		<div class="ngg-gallery-thumbnail" >
       <!-- se si vuole linkare alla foto grande mantenere solo il rpimo 'href=' altrimenti se si vuole linkare il link personalizzato mantenere solo il secondo 'href=' -->
       <?php
       	if ($image -> ngg_custom_fields ['link']=="") {
       ?>
       		<a>imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?>  rel="lightbox[<?php echo $gallery->anchor; ?>]"> 
   
       <?php
       			} else {
       ?>
         </a><a> ngg_custom_fields ['link'] ; ?>" target=_blank title="<?php echo $image->description ?>"
       <?php echo $image -> thumbcode ?> >
       <?php
       		}
       ?>
       				<?php if ( !$image->hidden ) { ?>
   
       				<img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> />
   
       				<?php } ?>
   
       			</a>
   
       		</div>
   
       	</div>
   
       	<?php if ( $image->hidden ) continue; ?>
   
       	<?php if ( $gallery->columns > 0 && ++$i % $gallery->columns == 0 ) { ?>
   
       		<br style="clear: both" />
   
       	<?php } ?>
   
        	<?php endforeach; ?>
   
       	<!-- Pagination -->
   
        	<?php echo $pagination ?>
   
       </div>
   
       <?php endif; ?>
       ```
   
 *  [mouli a11n](https://wordpress.org/support/users/mouli/)
 * (@mouli)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/#post-2868433)
 * I’m having the same issue.
    If you dump the image variable `var_dump($image)`
   you can see the item for item for the custom fields `["ngg_custom_fields"]=> 
   array(0) { } }` but its empty so I guess this plugin doesn’t work with WP3.4
 *  [mouli a11n](https://wordpress.org/support/users/mouli/)
 * (@mouli)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/#post-2868434)
 * [@kkri](https://wordpress.org/support/users/kkri/)
    I got it working by re writing
   my code. Not sure what was wrong the first time but it works now: In your example
   this looks wrong:
 *     ```
       <a> ngg_custom_fields ['link'] ; ?>" target=_blank title="<?php echo $image->description ?>"
       <?php echo $image -> thumbcode ?> >">
       ```
   
 * Maybe this would work better:
 * `<a href="<?php echo $image->ngg_custom_fields["website"] ?>" target="_blank"
   title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >`
 * then close the `</a>` tag after the image code.
 *  [sbaroulette](https://wordpress.org/support/users/sbaroulette/)
 * (@sbaroulette)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/#post-2868454)
 * Hi! Can someone who’s got it working please post their gallery.php so I can see
   how to link my images to external websites? I added the custom field ‘link’ but
   I’m having no luck and need a fix! Thanks!
 *  Thread Starter [Chris](https://wordpress.org/support/users/lamordnt/)
 * (@lamordnt)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/#post-2868455)
 * Here is a gallery.php page code. I did this awhile ago…
 *     ```
       <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?><?php if (!empty ($gallery)) : ?>
   
       	<div class="ngg-galleryoverview" id="<?php echo $gallery->anchor ?>">
   
       <h1><?php echo $gallery->title ?></h1>
   
       <?php if ($gallery->show_piclens) { ?>
       	<!-- Piclense link -->
       	<div class="piclenselink">
       		<a class="piclenselink" href="<?php echo $gallery->piclens_link ?>">
       			<?php _e('[View with PicLens]','nggallery'); ?>
       		</a>
       	</div>
       <?php } ?>
   
       	<!-- Thumbnails -->
       	<?php foreach ( $images as $image ) : ?>
   
       	<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box" >
       		<div class="ngg-gallery-thumbnail" >
       			<a href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >
       				<?php if ( !$image->hidden ) { ?>
       				<img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> />
       				<?php } ?>
       			</a>
       			<p class="img-title"><?php echo $image->alttext ?></p>
   
               <div class="img-caption-container">
       Image Credit: <a href="<?php echo $image->ngg_custom_fields["Image Link"]; ?>" target="_blank"><?php echo $image->ngg_custom_fields["Image Credit"]; ?></a>
       		</div><!--#img-caption-container-->
   
       		</div><!--.ngg-galler-thumnail-->
   
       	</div>
   
       	<?php if ( $image->hidden ) continue; ?>
   
       	<?php if ( $gallery->columns > 0 && ++$i % $gallery->columns == 0 ) { ?>
   
       		<br style="clear: both" />
   
       	<?php } ?>
   
        	<?php endforeach; ?>
   
       	<!-- Pagination -->
   
        	<?php echo $pagination ?>
   
       </div>
   
       <?php endif; ?>
   
       <div id="copy-protect">
       *All images and graphics are protected by the copyright rights of the artist that created them unless specifically noted to the contrary.   If you wish to use any of the images on this site please email the WLB at <a href="mailto:webmaster@lightthebridges.org" target="_blank">webmaster@lightthebridges.org</a> for use permission prior to doing so.
       </div>
       ```
   
 * And this is the actual snippet for the custom field from that page:
    `<a href
   ="<?php echo $image->ngg_custom_fields["Image Link"]; ?>" target="_blank"><?php
   echo $image->ngg_custom_fields["Image Credit"]; ?>`

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

The topic ‘[Plugin: NextGEN Custom Fields] Code for Gallery Field is Wrong’ is closed
to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/nextgen-gallery-custom-fields.svg)
 * [NextGEN Custom Fields](https://wordpress.org/plugins/nextgen-gallery-custom-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery-custom-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery-custom-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery-custom-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery-custom-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery-custom-fields/reviews/)

## Tags

 * [gallery id](https://wordpress.org/support/topic-tag/gallery-id/)

 * 6 replies
 * 5 participants
 * Last reply from: [Chris](https://wordpress.org/support/users/lamordnt/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-nextgen-custom-fields-code-for-gallery-field-is-wrong/#post-2868455)
 * Status: resolved