+1 to this.
I’ve attempted to add a custom function to my functions.php that adds the title into the img_caption_shortcode, but it just returns a blank, no title:
function fb_img_caption_shortcode($attr, $content = null) {
// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' )
return $output;
extract(shortcode_atts(array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => '',
'title' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . $id . '" ';
return '<dl ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px"><dt>' . do_shortcode( $content ) . '</dt><dd class="wp-caption-text"><em>' . $title . '</em>' . $caption . '</dd></dl>';
}
add_shortcode('wp_caption', 'fb_img_caption_shortcode');
add_shortcode('caption', 'fb_img_caption_shortcode');
Does anyone know how to grab the title out of the media library’s title field, and add it to the caption?
Hey alchymyth, thanks for that.
I saw that during my search over the last day. Unfortunately, this doesn’t solve my issue, as the solution posted at the bottom of that page by MosDave is more suitable to be placed in a template page.
I’m trying to filter and modify the caption via my functions.php file, throughout the entire site. I am adding thumbnails via the page editor on multiple pages, not running a query via the loop.
I’m curious how to use the solution that MosDave posted in combination with the filter to the wp_caption code… any clue?