I am using the popular and powerful NextGEN Gallery WordPress plugin to display my photography, and all of my picture posts now feature EXIF data: which camera I used, the focal length used, aperture and shutter speed. All this data is automatically extracted from the photos, so I don’t have to do anything to tell my readers a little more about each shot. In fact, NextGEN Gallery already includes this feature, it is just rather well-hidden! Let me tell you how to display EXIF data using NextGEN Gallery in your blog posts.
In my case, I want to show my reader a single large picture, so I am using NextGEN Gallery’s “singlepic” function. This gives me a relatively large photo that always has the right size for my post regardless of the original picture, but my readers can click on it to see the larger original picture on a black background. The file loaded by the plugin is called singlepic.php and is located in the /view/ directory under the wp-content/plugins/nextgen-gallery/ plugin directory. To display the EXIF data, we have to add some code to the singlepic.php file or create a new template file called singlepic-exif.php – a copy of the original file, where we add the lines to keep the original file intact and doing so also save our file from being overwritten by the next plugin update.
So, we have made a copy of singlepic.php, named it singlepic-exif.php and placed it in the same directory as the original file. The last lines of the file look like this:
…
<a href=”<?php echo $image->imageURL ?>” title=”<?php echo $image->linktitle ?>” <?php echo $image->thumbcode ?> >
<img src=”<?php echo $image->thumbnailURL ?>” alt=”<?php echo $image->alttext ?>” title=”<?php echo $image->alttext ?>” />
</a>
<?php if (!empty ($image->caption)) : ?><span><?php echo $image->caption ?></span><?php endif; ?>
<?php endif; ?>
To display the EXIF, we need to add a line after </a> like this:
…
<a href=”<?php echo $image->imageURL ?>” title=”<?php echo $image->linktitle ?>” <?php echo $image->thumbcode ?> >
<img src=”<?php echo $image->thumbnailURL ?>” alt=”<?php echo $image->alttext ?>” title=”<?php echo $image->alttext ?>” />
</a><p><?php echo $exif['camera'] ?>, <?php echo $exif['focal_length'] ?>. <?php echo $exif['aperture'] ?>, <?php echo $exif['shutter_speed'] ?>.
</p><?php if (!empty ($image->caption)) : ?><span><?php echo $image->caption ?></span><?php endif; ?>
<?php endif; ?>
This adds (as you might guess) information about your camera, focal length, aperture and shutter speed. You can also display ISO and date by replacing the names in the code. The only thing left to do now is to make sure you use the newly created singlepic-exif.php file. This is done by adding the code template=exif to the NextGEN Gallery shortcode in your blog post. So if your shortcode was
singlepic id=xxx w=320 h=240
then after adding the exif code, you get
singlepic id=xxx w=320 h=240 template=exif
- and that’s it! Now you know how to display EXIF data in your blog post with NextGEN Gallery. I learned about this over at the Japanese site lunablog, by the way!
Great, I dont know nothing about PHP, but I manage with your post. Thx!
Is it possible to do it with galleries and albums, instead of singlepic?
I’m not sure as I don’t really use galleries and albums, but EXIF information usually is part of the metadata of a single image. So what kind of EXIF data would you like to get from a gallery? All the individual photo values might be different…
Thanks!
Even with my little knowledge of PHP it works!
Finally I can put some Exif information next to my singlepic images