WordPress标题$ attr ['id']未显示

时间:2018-09-12 15:46:50

标签: php wordpress shortcode wordpress-shortcode

我的functions.php文件中有wordpress文档中的以下代码,但是$ attr ['id']不会显示在前端吗?知道Wordpress文档为何无法正确显示的任何想法(是的,确实添加了一个ID,将其设置为10)。

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>';

}

0 个答案:

没有答案