For one of my recent WordPress projects I needed an easy way for the client to organize and display videos. Unfortunately my hope that NextGen Gallery plugin, which I already used for the images, will do the trick vanished after couple of clicks and I started googling for a solution. Since neither google nor Worpdress Plugins page gave me anything reasonable I started rethinking the situation:
- I was already using Shadowbox which allows displaying videos
- I already had jQuery enabled in my WordPress Theme
- I can use the alt field in the NextGen options for the url of the video
So what I needed was to modify the generated from NextGen anchor (the href attribute) and somehow to distinguish if theĀ thumbnail is for image or video.
Here is the script I wrote which does both things:
1 2 3 4 5 6 7 8 |
jQuery(document).ready(function($){ $(".ngg-gallery-thumbnail a").each(function (arr){ if ($(this).attr("title").substr(0,5)=="Video"){ $(this).attr("rel","shadowbox;width=405;height=340"); $(this).attr("href",$(this).children("img").attr("title")); } }) }); |
All you have to do to make it work is:
- Include this Javascript somewhere on your page
- Put the url for your video in the alt textfield
- Start your descriptions with “Video”
If you found this script useful consider donating. Hosting isn’t free you know. Thanks!