Add a Custom URL to your WordPress Gallery Images
Now a WordPress plugin on Github: https://github.com/brewern/gallery-custom-link - This post has been updated now that the code is on Github.
By default each of your gallery images either have no link, file URL, or post URL. You can see this by viewing the images you have attached to your page. What if you wanted a custom link for each image in your gallery. This would be helpful if you wanted a gallery image to have an outbound link or link to a page on your site.
I read a few blog posts looking for this solution, one or two steered me in the right direction. Forgive me for not linking to those sources as I cannot remember how I found them.
After you have installed this plugin, upload a few images and add a gallery to your page. Edit that gallery and you can see the new text field we have added. Here is a before and after:
One last change to get the gallery to start showing your new custom link. Go to the HTML tab of the WordPress Wysiwyg and change the gallery shortcode link attribute to “custom”. IMPORTANT: the previous version of this plugin used the link value of “custom_url”, this has changed!
Change Gallery Shortcode
Important Note: Keep in mind that this plugin uses and overrides the core gallery function. Future WordPress versions could break this plugin, although it has lived through several. I’ll try to fix this plugin as soon as possible if it does break from an update. Leave a comment here or on Github in the event that it does break.