急いでいますので雑な記事ですが…
WORDPRESSの記事内でコメントアウトを使うとpタグが挿入されるのを防ぐ
WORDPRESSの記事内で画像やコメントアウトを使うとpタグが挿入されるのが非常に面倒なので pタグを削除する
function remove_p_on_images($content){
//画像のみpタグで囲わない
return preg_replace('/(\s*)(
)(\s*)/iU', '\2', $content);
}
add_filter('the_content', 'remove_p_on_images');
function remove_p_on_commentout($content){
//コメントアウトのみpタグで囲わない
return preg_replace('/
(\s*)()(\s*)/iU', '\2', $content);
}
add_filter('the_content', 'remove_p_on_commentout');
function remove_p_on_commentout2($content){
//コメントアウトのみpタグで囲わない
return preg_replace('/
(\s*)()(\s*)/iU', '\2', $content);
}
add_filter('the_content', 'remove_p_on_commentout2');
これで削除できた。コメントアウトは今回2種類使っていたので2種類書いておいた。





ディスカッション
コメント一覧
まだ、コメントがありません