Skip to content

Instantly share code, notes, and snippets.

@jmsmrgn
Last active December 23, 2015 16:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmsmrgn/5051735 to your computer and use it in GitHub Desktop.
Save jmsmrgn/5051735 to your computer and use it in GitHub Desktop.
WordPress - Filter <p> tags from images and iFrames
//Filter <p> tags from images and iFrames
function filter_ptags_on_images($content) {
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
return preg_replace('/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU', '\1', $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