Created
June 10, 2013 21:34
-
-
Save spigists/5752554 to your computer and use it in GitHub Desktop.
Stop images from getting wrapped in <p> tags when they are displayed with the_content()
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
/** | |
* Stop images from getting wrapped in the_content()'s <p> tags | |
*/ | |
function remove_img_ptags($content){ | |
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(\/a>)?\s*<\/p>/iU', '\1\2\3', $content); | |
} | |
add_filter('the_content', 'remove_img_ptags'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment