<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标签的高度与宽度让图片自适应屏幕》的一些看法。更多内容请查看本栏目更多内容!
下文提到的一切代码,都是增加到主题的funshions.php 文件的最初一个 ?> 的后面。 制造一个名为 login_logo...
上面引见四种WordPress 显示文章摘要办法: 一、应用WordPress自带摘要性能 我目前另一WordPress博客就是应...
因为国际大多冤家普通都是间接装置WordPress中文版,所以,倡萌在此以WordPress 3.4.2中文版进行演示。 1....
本文实例讲述了封闭wordpress新用户注册邮件告诉的办法。分享给大家供大家参考。详细剖析如下: wordpress博...
有一个一劳永逸的办法能够使wordpress博主当前上传插件都不必再手动激活,wordpress主动激活,办法很简略,...
某天用360的破绽检测,总共用了56分钟才检测完。 检测后果如图:破绽修复 破绽文件:(依据报警信息,修正这...