<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标签的高度与宽度让图片自适应屏幕》的一些看法。更多内容请查看本栏目更多内容!
确定要放在Head局部 ? 现实上最好的状况是,js文件都不要在<head>局部进行加载,否则会影响到head局部的...
本文实例讲述了WordPress小工具制造办法。分享给大家供大家参考,详细如下: WordPress是一个领有着无可比拟...
要害字形容:罕用 插件 代码 以及 &mdash 文章 即可   而后 统计 这篇文章是我之前为一个香港人...
WordPress的编辑器TinyMCE是一个十分弱小的工具,关于网页设计师来说,应用WordPress的编辑器TinyMCE是没什...
本文实例讲述了Dedecms待审核章在列表页显示的办法。分享给大家供大家参考。详细剖析如下: 昨天我写了一个...
一、评论提交超时: 大家可能会发现,在提交评论十分迟缓时最容易呈现“匿名”景象,这种状况次要...