img_caption_shortcode

最后更新于:2021-11-27 01:01:19

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

Filters the default caption shortcode output.

参数

$output

(string)
The caption output. Default empty.

$attr

(array)
Attributes of the caption shortcode.

$content

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

源文件

文件: gc-includes/media.php

View on Trac

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="gc-caption ' . esc_attr( $attr['align'] ) . '" '
	. 'style="max-width: ' . ( 10 + (int) $attr['width'] ) . 'px;">'
	. do_shortcode( $content )
	. '<p class="gc-caption-text">' . $attr['caption'] . '</p>'
	. '</div>';

}