Allows a plugin to replace the content that would otherwise be returned. The filter is 'img_caption_shortcode' and passes an empty string, the attr parameter and the content parameter values.
The filter should return a string containing the full HTML code that should be displayed. If it returns an empty string the standard WordPress functionality will be executed (see wp-includes/media.php
on line 629)
add_filter( 'img_caption_shortcode', 'my_img_caption_shortcode', 10, 3 ); function my_img_caption_shortcode( $empty, $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>'; }
As of WordPress 4.1 this hook is applied in the following location:
wp-includes/media.php
- on line 834As of WordPress 4.5 this hook is applied in the following location:
wp-includes/media.php
- on line 1458As of WordPress 4.6 this hook is applied in the following location:
wp-includes/media.php
- on line 1487