好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

移除WordPress文章图片的宽度和高度属性图解 - W

移除WordPress文章图片的宽度和高度属性图解

使用wordpress编辑器上传图片都会自动给图片增加宽度和高度,有时我们不希望有这相属性,下面我来给各位同学介绍移除WordPress文章图片的宽度和高度属性的方法.

如我个上传时会自动加属性,代码如下:

< img   title = "使用 Chrome Workspace 进行网站调试 | 倡萌的自留地 cmhello.com"   alt = "使用 Chrome Workspace 进行网站调试"   src = "/0019-cmhello_com.png"   width = "550"   height = "307"   />  

如果出于某些原因,你想去掉这个高度和宽度属性,可以将下面的代码添加到主题的 functions.php 文件即可,代码如下:

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 ;  } 

查看更多关于移除WordPress文章图片的宽度和高度属性图解 - W的详细内容...

  阅读:43次