Wordpress 3.9.x-从图形元素中删除行内宽度

Nic*_* J. 3 php wordpress figure shortcode

从Wordpress 3.9开始,您可以向functions.php添加一行代码,以告诉Wordpress输出带有更多语义图和figcaption元素的带有标题的图像:

add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
) );
Run Code Online (Sandbox Code Playgroud)

这很棒。但是由于某些原因,Wordpress为数字元素添加了宽度的内联样式,这阻止了整个单元的响应。那不是很好 我想向functions.php添加一些代码,以告诉Wordpress不包括行内宽度。

在media.php文件中,我找到了解决我的问题的标题简短代码:

$output = apply_filters( 'img_caption_shortcode', '', $attr, $content );
if ( $output != '' )
return $output;

$atts = shortcode_atts( array(
'id'      => '',
'align'   => 'alignnone',
'width'   => '',
'caption' => '',
'class'   => '',
), $attr, 'caption' );

$atts['width'] = (int) $atts['width'];
if ( $atts['width'] < 1 || empty( $atts['caption'] ) )
return $content;

if ( ! empty( $atts['id'] ) )
$atts['id'] = 'id="' . esc_attr( $atts['id'] ) . '" ';

$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );

if ( current_theme_supports( 'html5', 'caption' ) ) {
return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr( $class ) . '">'
. do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
}
Run Code Online (Sandbox Code Playgroud)

有什么想法如何从图形元素中删除内嵌样式宽度?

编辑:我在这里找到解决方案。

Jon*_*man 6

您的问题一个过滤器:

有什么想法如何从图形元素中删除内嵌样式宽度?

add_filter('img_caption_shortcode_width', '__return_false');
Run Code Online (Sandbox Code Playgroud)

这使得Figure元素没有任何样式属性废话