<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自带的评论性能来做的话...
上面引见四种WordPress 显示文章摘要办法: 一、应用WordPress自带摘要性能 我目前另一WordPress博客就是应...
flush_rewrite_rules() 函数用来删除而后依据现有的条件重写伪动态规定,也就是刷新一次伪动态规定了。 先来...
style.css : CSS(款式表)文件,普通包括主题申明和通用css款式代码 index.php : 主页模板,普通用来做网...
本文实例讲述了WordPress评论制止针对指定内容全英文的办法。分享给大家供大家参考。详细剖析如下: WordPr...
有意中发现一款性能弱小的Wordpress代码高亮插件 – Crayon Syntaxer,我以为能够算是目前款式最多、易...