apply_filters( ‘img_caption_shortcode’, string $output, array $attr, string $content )

Filters the default caption shortcode output.

Description

If the filtered output isn’t empty, it will be used instead of generating the default caption template.

See also

Parameters

$outputstring
The caption output. Default empty.
$attrarray
Attributes of the caption shortcode.
$contentstring
The image element, possibly wrapped in a hyperlink.

Source

$output = apply_filters( 'img_caption_shortcode', '', $attr, $content );

Changelog

VersionDescription
2.6.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    add_filter( 'img_caption_shortcode', 'my_img_caption_shortcode', 10, 3 );
    
    function my_img_caption_shortcode( $output, $attr, $content ) {
    	$attr = shortcode_atts( array(
    		'id'      => '',
    		'align'   => 'alignnone',
    		'width'   => '',
    		'caption' => ''
    	), $attr );
    
    	if ( 1 > (int) $attr['width'] || empty( $attr['caption'] ) ) {
    		return '';
    	}
    
    	if ( $attr['id'] ) {
    		$attr['id'] = 'id="' . esc_attr( $attr['id'] ) . '" ';
    	}
    
    	return '<div ' . $attr['id']
    	. 'class="wp-caption ' . esc_attr( $attr['align'] ) . '" '
    	. 'style="max-width: ' . ( 10 + (int) $attr['width'] ) . 'px;">'
    	. do_shortcode( $content )
    	. '<p class="wp-caption-text">' . $attr['caption'] . '</p>'
    	. '</div>';
    
    }

You must log in before being able to contribute a note or feedback.