php – WordPress 3.9.x – 从图元素中删除内联宽度

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – WordPress 3.9.x – 从图元素中删除内联宽度脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
wordpress 3.9开始,您可以向functions.PHP添加一行代码,告诉wordpress输出带有更多语义图和figcaption元素的标题的图像:

add_theme_support( 'htML5',array(
'seArch-form','comment-form','comment-list','gallery','caption'
) );

这很棒.但由于某些原因,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'   => '',),'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>';
}

任何想法如何从图元素中删除内联样式宽度?

编辑:我找到了@L_406_24@案here.

解决方法

您的问题有一个过滤器:

add_filter('img_caption_shortcode_width','__return_false');

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

脚本宝典总结

以上是脚本宝典为你收集整理的php – WordPress 3.9.x – 从图元素中删除内联宽度全部内容,希望文章能够帮你解决php – WordPress 3.9.x – 从图元素中删除内联宽度所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。