Skip to content

Instantly share code, notes, and snippets.

@fueledbyboredom
Created February 14, 2017 16:14
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 fueledbyboredom/3da62c44fdf4d120089c13bfe4e507ed to your computer and use it in GitHub Desktop.
Save fueledbyboredom/3da62c44fdf4d120089c13bfe4e507ed to your computer and use it in GitHub Desktop.
Strip <p> tags from images that are outputted via the_content().
<?php
function mwpf_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', 'mwpf_remove_img_ptags');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment