<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主动给文章增加nofollow属性的完成办法。分享给大家供大家参考。详细剖析如下: no...
比方本人创立了一个主题,那么需求在后盾增加一些设置选项,所以就触及到了后盾增加顶级菜单的需要: 复制代...
作为一款遭到大少数站长欢送的内容治理零碎,WordPress不只有着弱小的治理性能,而且应用不便,即便是老手也...
找到wp-includes/comment-template.php文件中 复制代码代码如下:if ( empty( $url ) || 'http://' == $url ...
get_category get_category 可能咱们平常接触的不多,但却是很有用,网上这个函数引见的貌似不多,所以明天...
本文实例讲述了WordPress完成网站投稿者也能够上传图片的办法。分享给大家供大家参考。详细剖析如下: Word...