Builds the Caption shortcode output.
Allows a plugin to replace the content that would otherwise be returned. The
filter is {@see ‘img_caption_shortcode’} and passes an empty string, the attr
parameter and the content parameter values.
The supported attributes for the shortcode are ‘id’, ‘caption_id’, ‘align’,
‘width’, ‘caption’, and ‘class’.
function img_caption_shortcode( $attr, $content = '' ) {
// New-style shortcode with the caption inside the shortcode with the link and image tags.
if ( ! isset( $attr['caption'] ) ) {
if ( preg_match( '#((?:]+>s*)?]+>(?:s*)?)(.*)#is', $content, $matches ) ) {
$content = $matches[1];
$attr['caption'] = trim( $matches[2] );
}
} elseif ( strpos( $attr['caption'], ' '',
'caption_id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => '',
'class' => '',
),
$attr,
'caption'
);
$atts['width'] = (int) $atts['width'];
if ( $atts['width'] %s%s',
$id,
$describedby,
$style,
esc_attr( $class ),
do_shortcode( $content ),
sprintf(
'%s',
$caption_id,
$atts['caption']
)
);
} else {
$html = sprintf(
'%s%s
',
$id,
$style,
esc_attr( $class ),
str_replace( '%s',
$caption_id,
$atts['caption']
)
);
}
return $html;
}