Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function remove_p_on_images($content){ | |
//画像のみpタグで囲わない | |
return preg_replace('/<p>(\s*)(<img .* \/>)(\s*)<\/p>/iU', '\2', $content); | |
} | |
add_filter('the_content', 'remove_p_on_images'); | |
?> |
Screen shot
Note
Description | 画像を囲うpタグに限定して削除する場合は正規表現で置換する。wpautopでも出来そうだけど、置換したほうが楽そう。 |
---|---|
WordPress Ver. | 3.5 |
Via | Stop WordPress Wrapping Images In A “P” Tag |