The WordPress media manager allows you to add captions to your images, which can be inserted into your post content wrapped in the caption shortcode.
[ caption id="attachment_1133" align="alignleft" width="300"
Now, the HTML entities have to be escaped in order to safely place them in the caption=”” attribute of the caption shortcode (or at least the double quotes do), and in any event it’s very inconvenient to decode the entities manually. What we’ll need to do is decode them programmatically when the shortcode is processed at run time.
* parameter and the content parameter values.
* @param string $content Optional. Shortcode content.
We’re just going to hook in and use the same code, but add a line of our own to decode the HTML tags.
And that’s it! Just pop that code into your functions.php and you should be able to add links to your photo captions. If anyone knows a better way of doing this, let me know in the comments. Enjoy!
This entry was posted in Code, WordPress Tutorials and tagged captions, how to, images, shortcodes, WordPress. Bookmark the permalink.
I am kind of stuck on this as well. I need the description only for an image glelary and then use the attachments to the page to actually describe the galleries. Like a short code for a glelary, puts the id’s of each image, and then it grabs the description and title for them.
I put the final code in my functions file, and did a test caption with a link. It looked perfect until I saved the page with them image – and then everything stripped back out. I didn’t get the encoded version, I just ended up with the text only – all the anchor tag information stripped out.
Do I still need to escape the double quotes in the caption field?
I’m using iThemes Builder with a child theme, if that affects this solution.
Great function. I’m in a siiatuton where I need to add the description to old content where images are already embedded. Anyway to get the image description to show up on the edit image popup? For some reason it’s different than the add image pop up.