Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove auto p tags around images
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
/* Originally posted @ https://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.