Created
June 14, 2012 20:13
-
-
Save stellarcowboy/2932639 to your computer and use it in GitHub Desktop.
Stop wordpress from wrapping images in <p> tags
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 wordpress from wrapping images in <p> tags | |
function filter_ptags_on_images($content) | |
{ | |
// do a regular expression replace... | |
// find all p tags that have just | |
// <p>maybe some white space<img all stuff up to /> then maybe whitespace </p> | |
// replace it with just the image tag... | |
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); | |
} | |
// we want it to be run after the autop stuff... 10 is default. | |
add_filter('the_content', 'filter_ptags_on_images'); | |
//http://snipplr.com/users/rliverman/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment