<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完成搜寻后果只有一篇文章时主动跳转到文章的办法。分享给大家供大家参考。详细剖析...
插件称号:多备份 插件下载:http://www.dbfen.com/tools/dbfen_wordpress_20141112.zip 第1步下载紧缩包后...
WordPress自带的条件标签能够让你根据条件显示不同的内容,比方,你能够反省用户是在首页?能否登陆? PHP if(语...
友谊链接关于一个每个独立博客来说能够说是必需的,有不少人抉择在侧边栏退出友谊链接栏目,但建设一个独立...
现在,WordPress CMS 主题越来越多,WordPress 作为 CMS 终究有那些共同的劣势,吸援用户去一直的延长扩大呢...
一、发现成绩 在尝试编辑博客站点的Wordpress主题时,忽然发现博客站点无奈衔接;刷新后提醒“建设数据库衔...