<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标签的高度与宽度让图片自适应屏幕》的一些看法。更多内容请查看本栏目更多内容!
登陆邮件提示完成办法 前提是空间有邮件性能,测试有无邮件性能的办法:登录界面点击“遗记明码”,有邮件...
调用最新文章: 复制代码代码如下: <ul> <?php $post_query = new WP_Query(‘showposts=10′); ...
办法一:应用<!--more-->标签来自在的截取字数 在模板中应用the_content()函数来打印内容,在文章中经过点击...
比方本人创立了一个主题,那么需求在后盾增加一些设置选项,所以就触及到了后盾增加顶级菜单的需要: 复制代...
上面是详细处理流程:1 首先关上phpadmin,从右边的表中抉择xx_opition2 在xx_opition中进行查问,在查问框...
WordPress在后盾编辑日志时编辑框左下角有一个字数统计,不过只显示在后盾,能不能在前台也加上文章字数统计...