3

I would like to add a link to the caption of a photo in one of my posts. I can type in the HTML for the link in the caption, but when I publish the post the link gets removed.

How do you add a link to a caption? This would be really useful for giving photo credit.

4 Answers 4

1

See my answer on question 3097 for a possible solution.

1

I wanted to be able to use the media attachment's title, description, and maybe even the permalink and image link too. I felt that a caption specific hook should be added to the media.php file.

When I went to submit an enhancement request, it looked like someone beat me to it. Unfortunately, that was four years ago. I bumped it.

In the meantime, I published the GIC plugin to add this caption hook for me. Once the plugin is installed, you can write a filter to use more media attachment meta as your caption. With a filter, you can even add more styling or remove/hide the caption completely.

Here's an example filter that pulls in the image's title, caption, description, creates a download link, and adds some custom styles.

/**
 * Custom Filter for Gallery Image Captions
 */
function my_gallery_image_caption($attachment_id, $captiontag, $selector, $itemtag) {

    $id = $attachment_id;

    $my_image_meta = galimgcaps_get_image_meta($id);

    return "<{$captiontag} class='wp-caption-text gallery-caption' id='{$selector}-{$id}'>"
    . "<strong>" .  wptexturize($my_image_meta['title']) . "</strong><br><br>"
    .  wptexturize($my_image_meta['caption']) . "<br><br>"
    .  wptexturize($my_image_meta['description']) . "<br><br>"
    . "<strong>Alt Text</strong>: " . $my_image_meta['alt'] . "<br><br>"
    . "<a href='" . $my_image_meta['src'] . "' target='_blank'>Download Image</a>"
    . "</{$captiontag}></{$itemtag}>";

}
add_filter('galimgcaps_gallery_image_caption', 'my_gallery_image_caption', 10, 4);

Check out the documentation and examples to see if this works for you. Shout if you have any questions.

0

Do you want the link under the photo, on top of the photo, or when you click the photo is goes to the caption?

1
  • Under the photo and associated with the image in the caption field when you upload it and in your media gallery. Sep 17, 2010 at 12:40
0

Same question at wordpress support forum http://wordpress.org/support/topic/putting-a-link-in-an-image-caption .. see if these work around work for you.

Best of Luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.