Skip to content

Instantly share code, notes, and snippets.

@spigists
Created June 10, 2013 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spigists/5752554 to your computer and use it in GitHub Desktop.
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()
/**
* 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