<img src="abc.png" alt="abc" width="580" height="267" />
<img src="abc.png" alt="abc" />
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;
}
// 自顺应图片删除width和height,by Ludou
function ludou_remove_width_height_attribute($content){
preg_match_all("/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png\.bmp]))[\'|\"].*?[\/]?>/", $content, $images);
if(!empty($images)) {
foreach($images[0] as $index => $value){
$new_img = preg_replace('/(width|height)="\d*"\s/', "", $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
return $content;
}
// 判别能否是挪动设施阅读
if(wp_is_mobile()) {
// 删除文章内容中img的width和height属性
add_filter('the_content', 'ludou_remove_width_height_attribute', 99);
}
以上就是安达网络工作室关于《WordPress去除img标签的高度与宽度让图片自适应屏幕》的一些看法。更多内容请查看本栏目更多内容!
在没有本人的网站的时分很想领有一个属于本人的网站,能够说是本人的一个欲望吧。然而当我真正的运转起来了...
WordPress有着比拟弱小的分类机制,包括文章分类、标签等,弱小的分类机制能够用来完成门户网站的相似二级频...
关于一个刚接触Wordpress的老手来说,或多或少都会遭到网络上对于Wordpress的一些评论影响。有的甚至被奉为...
本文实例讲述了WordPress小工具制造办法。分享给大家供大家参考,详细如下: WordPress是一个领有着无可比拟...
函数引见 update_option()用于更新数据表中存在的选项值。该函数可取代add_option,但不迭add_option灵敏。...
本人平常用到的一些函数,整顿一下,大家有用到来拿吧,我怕放电脑上不见了,当前又得找。 Index page 首页...