Skip to content

Instantly share code, notes, and snippets.

@anestan
Created November 30, 2016 08:19
Show Gist options
  • Save anestan/c273c647f1a5398c8746caf0fdab1c08 to your computer and use it in GitHub Desktop.
Save anestan/c273c647f1a5398c8746caf0fdab1c08 to your computer and use it in GitHub Desktop.
Remove P Tags From Images - Wordpress
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