<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标签的高度与宽度让图片自适应屏幕》的一些看法。更多内容请查看本栏目更多内容!
复制代码代码如下: <?php //Put this in functions.php function get_primary_image($id, $size){ ...
有时分将不同类型的文件分门别类存储,仿佛比年月目录更无意义。例如幻灯片应该存储在slides目录下,下载文...
渣滓评论曾经不是一个新颖的货色了,置信只需是日独立IP超越2000的网站,只需开放评论的话,每天都会收到几...
上面是详细处理流程:1 首先关上phpadmin,从右边的表中抉择xx_opition2 在xx_opition中进行查问,在查问框...
本文只限Apache配置主机的应用办法,添加WordPress文件上传大小限度:经过配置php.ini的upload_max_filesiz...
自定义 WordPress 默许评论头像 关于没有设置Gravatra头像的评论者来说,WordPress会显示一个你在后盾设置的...