<a
のところを<img
にすれば良いのでは…?
nobitaさんのをコピペしただけですが。
add_filter( 'image_send_to_editor', 'remove_img_attr' );
function remove_img_attr( $html ) {
$class = 'you-need';
return str_replace( '<img ', '<img class="'. $class. '" ', $html );
}
早速ありがとうございます!
前にご指摘通り試してうまくいかなかったので投稿してしまいましたが、何か間違えていたようで今度はうまくいきました。ありがとうございました。
ただ、class追加はされていたのですがもともと入っているclassと別に表記されてしまうのです。
【例】<img src=”○○” class=”you-need” (中略)class=”size-large wp-image-○○” />
これは仕方ないものでしょうか。
【例】<img src=”○○” class=”you-need” (中略)class=”size-large wp-image-○○” />
これは仕方ないものでしょうか。
img 要素の中で、class属性は、1回しか使えないので、下のようにしてみてはどうでしょうか
add_filter( 'image_send_to_editor', 'remove_img_attr' );
function remove_img_attr( $html ) {
$class = 'you-need';
return preg_replace( '!(<img[^>]+class=")!', '$1'.$class.' ', $html );
}