售前咨询400-838-0503

教你WordPress批量删除图片高度和宽度参数

技术文档 2024-12-26 20:41

我们有些时候采编到的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;
}

如本公告涉及你的产品,或有不清楚之处,可提交工单确认。

提交工单