php – WordPress 3.9.x – 从图元素中删除内联宽度
发布时间:2020-12-13 21:51:30 所属栏目:PHP教程 来源:网络整理
导读:从Wordpress 3.9开始,您可以向functions.php添加一行代码,告诉Wordpress输出带有更多语义图和figcaption元素的标题的图像: add_theme_support( 'html5',array('search-form','comment-form','comment-list','gallery','caption') ); 这很棒.但由于某些原因,
从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>'; } 任何想法如何从图元素中删除内联样式宽度? 编辑:我找到了解决方案here. 解决方法
您的问题有一个过滤器:
add_filter('img_caption_shortcode_width','__return_false'); 这使得图元素没有任何样式属性废话 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |