
Just check out those ducks to the right. They look content, don’t they? I imagine that being a duck must be a pretty good life. Hang out in the pond, wait for the little old lady to come along with some bread, hang out a bit more…life could be worse. Plus they are freaking waterproof. I mean, I know we technically are too, but the phrase is “like water off a duck’s back”, not “like water off a WordPress user’s back”.
But I digress. My point is, the photo of those ducks came courtesy of Dustin and Jenae. Unfortunately, I was unable to link back to their Flickr profile in the photo’s caption, because WordPress just plain won’t let me.
Although WordPress generally functions in an intuitive manner, it still has some peculiar idiosyncrasies. One of those idiosyncrasies is its habit of stripping HTML markup from captions. Most irritatingly, it destroys hyperlinks.
Image attribution is not the only reason you might want to include links in image captions. But forget the reasons – what is the solution? Well, you have three options. Let’s take a look at them.
1. HTML Editor Workaround
This one is simple, but will only be of use to the most hardcore of WordPress users. If you do not use the Visual Editor, inserting links into image captions with the HTML editor is as simple as following the normal process, but making sure that you use single quotes (‘) instead of double quotes (“) in the relevant places. For example:
<a href='http://www.example.com' title='Click me'>No double quotes were harmed in the making of this link.</a>
As long as you don’t switch into the Visual Editor, the above method will work fine. If you do switch into the visual editor, both the link and anchor text will vanish.
2. The Plugin Solution
The far easier solution is to install the aptly-named Links In Captions plugin. Once you have done so, you just need to include links using either of the following two formats:
{a href="http://www.example.com"}Anchor text here{/a}
{link url="http://www.example.com"}Anchor text here{/link}
You can also add the target, title and rel attributes to your links, like this:
{link url="http://www.example.com" target="_blank" rel="nofollow" title="I never could do this before!"}Anchor text here{/link}
Simple! Although you do not have the luxury of inserting hyperlinks in the usual super-convenient way, it is a functional workaround that gets the job done.
3. Wait
This is perhaps the laziest option. Ticket #18311 in the WordPress Trac was recently “blessed” by the powers that be, and the feature is planned to be incorporated into version 3.4 of WordPress. That feature is, of course, the ability to add HTML markup to captions.
So not only will you be able to add links, but you will be able to use all of the usual HTML formatting tags without WordPress getting angry and deleting all of your good work.