Full Text

One of the hacks I put in place for my new site design was to get image titles to display when you click on an image in the gallery. This isn’t out-of-the-box functionality for the NextGEN plugin; the description (which you set manually in the gallery manager) is populated, but the image title is not. The solution lies in modifying the title attribute of the a tag generated by gallery.php. To see an example of this hack in action for images with and without descriptions, visit the Space Needle pictures gallery and click on the last two images in the set. One shows only the image title, the other shows title and description. Code after the fold.

Update 11.19.2010: Now with EXIF! (maybe)

Caveats/Notes:

This works for the thickbox effect. I don’t know if will work for other effects.

Directly editing the PHP files of plugins may cause problems when you update WordPress or the plugin itself. Do so at your own risk.

The bold tags look great, but I’m not sure how compatible they are; your mileage may vary.

Successfully tested on Firefox, IE8, Chrome (webkit).

PHP Code: Step 1
Find this code in wp-content/plugins/nextgen-gallery/view/gallery.php (line 38 in unmodified original version 1.3.5):

Explanation:
thickbox.js, a WordPress include, is the javascript that generates the image popup for NextGEN’s thickbox effect. It gets its information from the thumbnail href in the gallery and uses that information to populate picture data in the popup’s caption area beneath the picture. Specifically, the picture’s description is pulled from the title attribute of the image’s a tag which is, in turn, generated in gallery.php by the code above. Unmodified, the code only pulls the description, which you can set in the gallery manager area. By adding this code, you’re prepending the image name to the description and passing that to thickbox.js via the thumbnail title text. If no description is present, only the image title is passed to thickbox.

You can see how the new variable $newdesc can be manipulated to include any other data you want. For example, you could also append exif data and image size by appending $exif[‘created_timestamp’] and $image->size to $newdesc. To see what information is available to you, add the PHP function <?php var_dump($image) ?> inside the foreach loop and it will output all of the attributes of each image.

EXIF Update 11.19.2010:
After some messing around, I’ve sorted out a way to access the EXIF data, since the method provided by the developer doesn’t work. Let me know how this goes for you. The new code required to add EXIF data is now included above. The sample EXIF data I appended to $newdesc on line 18 is the date information. Here is the key for other data:

title: $pdata->get_META(‘title’)

caption: $pdata->get_META(‘caption’)

keywords: $pdata->get_META(‘keywords’)

timestamp: $pdata->get_date_time()

date stamp only: substr($pdata->get_date_time(),0,10)

Feel free to share any improvements, limitations, etc. in the comments.

Just found this tip. I tried it, and it works. But now whenever I click on an image in a gallery, two slideshows pop up (one without the descriptions, and another with the descriptions). How do I get rid of the extra unwanted one?

I have tried to use this as it’s exactly what I want to do. I cannot get it to work though. I am using NextGen Version 1.9.8 and WordPress 3.4.2. Using jQuery library version 1.8.2 from Google instead of the one that comes with WordPress. No difference whichever jQuery I use. I have also deactivated all other plugins. Any ideas what could be wrong?

I have got the descriptions appearing on the larger image OK but the descriptions are coming up under the thumbnails too. Because they are more than several words long, the description is displacing the thumbnails. When the cursor hovers over the thumbnail the short title appears as the alt_text which is great.

How can I not have the longer description under the thumbnails but still appear on the larger image?

I am sure that this is an isty bitsy change in the code, but what is it I should alter?

i don’t suppose you want to update this to work with the latest version of nextgen….? it looks like they reworked some stuff and the basic hack doesn’t seem to work anymore; i’m sure it’s something minor that i can’t figure out…

New version looks really nice; it appears they’ve done a complete overhaul. I’ll have to check it out and see if there’s a way to get titles in there. I’m really surprised that isn’t supported out-of-the-box. Seems like such a simple and obvious feature.

Would be cool if you could get the EXIF data to display with the new version. Your correct on a complete overhaul and all my old data doesn’t work anymore since I updated to the most recent NextGen version. I’ve tried everything to get it to work and no luck. Agreed sure seems simple and obvious?

I had a problem at one vitegtne. I made the change on the file gd.thumbnail.inc.php. I still have the same problem. With the error message: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 920 bytes) in / htdocs / wp-content / plugins / nextgen-gallery / lib / gd.thumbnail.inc.php on line 436