wp-includes/media.php:2628Builds the Caption shortcode output.
$attrarray$idstring
$caption_idstring
$alignstringdefault: 'alignnone'. Accepts 'alignleft', 'aligncenter', alignright', 'alignnone'
$widthint
$captionstring
$classstring
$contentstringoptional''string2 hooks fire while img_caption_shortcode() runs, in this order:
Filters the default caption shortcode output.
Filters the width of an image's caption.
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( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) { $content = $matches[1]; $attr['caption'] = trim( $matches[2] ); } } elseif ( str_contains( $attr['caption'], '<' ) ) { $attr['caption'] = wp_kses( $attr['caption'], 'post' ); } /** * Filters the default caption shortcode output. * * If the filtered output isn't empty, it will be used instead of generating * the default caption template. * * @since 2.6.0 * * @see img_caption_shortcode() * * @param string $output The caption output. Default empty. * @param array $attr Attributes of the caption shortcode. * @param string $content The image element, possibly wrapped in a hyperlink. */ $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); if ( ! empty( $output ) ) { return $output; } /** * @var array{ * id: string, * caption_id: string, * align: string, * width: string, * caption: string, * class: string, * } $atts */ $atts = shortcode_atts( array( 'id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => '', ), $attr, 'caption' ); $atts['width'] = (int) $atts['width']; if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) { return $content; } $id = ''; $caption_id = ''; $describedby = ''; $unique_id_value = ''; $caption_id_value = ''; if ( $atts['id'] ) { $atts['id'] = sanitize_html_class( $atts['id'] ); $unique_id_value = (string) preg_replace( '/-1$/', '', wp_unique_prefixed_id( $atts['id'] . '-' ) ); $id = 'id="' . esc_attr( $unique_id_value ) . '" '; } if ( $atts['caption_id'] ) { // User explicitly provided a caption_id - make it unique. $atts['caption_id'] = sanitize_html_class( $atts['caption_id'] ); $caption_id_value = preg_replace( '/-1$/', '', wp_unique_prefixed_id( $atts['caption_id'] . '-' ) ); } elseif ( $unique_id_value ) { // Derive from the already-unique figure ID - guaranteed unique, no need for second call. $caption_id_value = 'caption-' . str_replace( '_', '-', $unique_id_value ); }Introduced in 2.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/media.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.