I use a custom gallery function to alter the normal Wordpress markup. Usually it's fine but I can't quite figure out how to add the image caption as a TITLE attribute on the thumbnail link. (The lightbox I'm using turns the title attribute into a caption.)
Here's the relevant code from the filter:
foreach ( $attachments as $id => $attachment ) {
$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$link = str_replace('><img','title="test caption" ><img',$link);
$output .= "<{$itemtag} class='item'>";
$output .= "
$link
";
if ( $captiontag && trim($attachment->post_content) ) {
$output .= "
<{$captiontag}>
" . wptexturize($attachment->post_content) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
if ( $columns > 0 && ++$i % $columns == 0 )
$output .= '';
}
$output .= "
<br>\n";
return $output;
}
That second $link
line with str_replace
is as far I've gotten. I thought maybe I could get wp_get_attachment_link to output a title attribute, and when I couldn't find a solution I used str_replace but I don't know how to get the image caption where the words "test caption" currently are.
$j('figure a img').each(function(idx, element) { $j(element).parent().attr('title',$j(element).attr('alt')); });