LoginSignup
1
1

More than 5 years have passed since last update.

WordPress: 投稿時のimageタグから要らない記述を消す【functions.php】

Posted at

↓title="" class="" height="" を消してみる

functions.php
/**
 * 投稿時のimageタグから要らない記述を消す
 */
add_filter('get_image_tag', 'remove_img_attr', 10, 6);
add_filter('post_thumbnail_html', 'remove_img_attr', 10);

function remove_img_attr($html)
{
  $html = preg_replace('/title=[\'"]([^\'"]+)[\'"]/i', '', $html);
  $html = preg_replace('/ class=[\'"]([^\'"]+)[\'"]/i', '', $html);
  $html = preg_replace('/(height)="\d*"\s/', '', $html);
  return $html;
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1