Warning: Trying to access array offset on value of type bool in /home/r-design001/hp-r-design.com/public_html/wp-content/themes/source_tcd045/single.php on line 22

メディア追加時の自動で挿入される「画像挿入時にwidthとheightやCSSを削除する」方法

メディア追加時の自動で挿入される「画像挿入時にwidthとheightやCSSを削除する」方法をご紹介いたします。

wordpressのテーマ内にありますfunction.phpに以下を追記すると、メディア追加時にwidthとheightが入らずに更新できます。

 

add_filter( 'image_send_to_editor', 'remove_image_attribute', 10 );
add_filter( 'post_thumbnail_html', 'remove_image_attribute', 10 );

function remove_image_attribute( $html ){
$html = preg_replace( '/(width|height)="\d*"\s/', '', $html );
$html = preg_replace( '/class=[\'"]([^\'"]+)[\'"]/i', '', $html );
$html = preg_replace( '/title=[\'"]([^\'"]+)[\'"]/i', '', $html );
$html = preg_replace( '/<a href=".+">/', '', $html );
$html = preg_replace( '/<\/a>/', '', $html );
return $html;
}

関連記事

  1. ★WORDPRESS よく利用するタグまとめ★

  2. 【ドメイン】各レコードの意味(解説)について

  3. アナリティクスのタグを複数設置する正しいやり方

  4. ループを連続で使用する場合の注意点 wp_reset_postdata…

  5. WEBサイトにInstagramを簡単に表示できるjQueryをご紹介…

  6. 1つのWEBサイトに複数のトラッキングコードを設置する方法