我们有些时候采编到的WordPress图片是带有宽度和高度尺寸参数的,我们需要批量删除,这里可以直接用这么一段代码实现。 //干掉默认的图片宽度以及高度 add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 ); add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 ); function remove_width_attribute( $html ) { $html = preg_replace( '/(width|height)="\d*"\s/', "", $html ); return $html; }