Skip to content

Instantly share code, notes, and snippets.

@andyknapp
Created March 31, 2014 12:31
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 andyknapp/9891272 to your computer and use it in GitHub Desktop.
Save andyknapp/9891272 to your computer and use it in GitHub Desktop.
Strip <p> tags from images within the_content in WordPress
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment