img_caption_shortcode

函数


img_caption_shortcode ( $attr, $content = '' )
参数
  • (array)
    $attr
    { Attributes of the caption shortcode. @type string $id ID of the image and caption container element, i.e. `
    ` or `
    `. @type string $caption_id ID of the caption element, i.e. `
    ` or `

    `. @type string $align Class name that aligns the caption. Default ‘alignnone’. Accepts ‘alignleft’, ‘aligncenter’, alignright’, ‘alignnone’. @type int $width The width of the caption, in pixels. @type string $caption The caption text. @type string $class Additional class name(s) added to the caption container. }

    Required:
  • (string)
    $content
    Optional. Shortcode content. Default empty string.
    Required:
    Default: (empty)
  • 返回值
    • (string) HTML content to display the caption.
    定义位置
    • wp-includes/media.php
      , line 2193
    引入
    2.6.0
    弃用

    Builds the Caption shortcode output.

    Allows a plugin to replace the content that would otherwise be returned. The
    filter is {@see ‘img_caption_shortcode’} and passes an empty string, the attr
    parameter and the content parameter values.

    The supported attributes for the shortcode are ‘id’, ‘caption_id’, ‘align’,
    ‘width’, ‘caption’, and ‘class’.

    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( '#((?:]+>s*)?]+>(?:s*)?)(.*)#is', $content, $matches ) ) {
    			$content         = $matches[1];
    			$attr['caption'] = trim( $matches[2] );
    		}
    	} elseif ( strpos( $attr['caption'], ' '',
    			'caption_id' => '',
    			'align'      => 'alignnone',
    			'width'      => '',
    			'caption'    => '',
    			'class'      => '',
    		),
    		$attr,
    		'caption'
    	);
    
    	$atts['width'] = (int) $atts['width'];
    
    	if ( $atts['width'] %s%s',
    			$id,
    			$describedby,
    			$style,
    			esc_attr( $class ),
    			do_shortcode( $content ),
    			sprintf(
    				'
    %s
    ', $caption_id, $atts['caption'] ) ); } else { $html = sprintf( '
    %s%s
    ', $id, $style, esc_attr( $class ), str_replace( '%s', $caption_id, $atts['caption'] ) ); } return $html; }