<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标签的高度与宽度让图片自适应屏幕》的一些看法。更多内容请查看本栏目更多内容!
办法一:应用<!--more-->标签来自在的截取字数 在模板中应用the_content()函数来打印内容,在文章中经过点击...
关于一个刚接触Wordpress的老手来说,或多或少都会遭到网络上对于Wordpress的一些评论影响。有的甚至被奉为...
最近关上博客后盾,发现后盾关上速度很慢。 经过开发者调试工具对网络加载进行检测,发现是因为后盾应用了谷...
WordPress在线装置主题、插件,或在应用疾速公布的文章中含有图片时,会提醒: 正在装置主题:Frontier 1.0...
最近在做一个客户的企业网站建立时,需求往数据库提交信息的表单页面,然而Wordpress自带的评论性能来做的话...
在主题的function.php文件中,能够找到形如如下内容的语句:复制代码代码如下:if ( function_exists(&lsquo...