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.

Top ↑

See also


Top ↑

Parameters

$output

(string) The caption output. Default empty.

$attr

(array) Attributes of the caption shortcode.

$content

(string) The image element, possibly wrapped in a hyperlink.


Top ↑

Source

File: wp-includes/media.php

View on Trac



Top ↑

Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    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.