Skip to content

Instantly share code, notes, and snippets.

@noellesteegs
Created April 10, 2020 12:30
Show Gist options
  • Save noellesteegs/1499614c1256b2f59c87092a58dbc260 to your computer and use it in GitHub Desktop.
Save noellesteegs/1499614c1256b2f59c87092a58dbc260 to your computer and use it in GitHub Desktop.
Remove auto p tags around images
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');
/* Originally posted @ https://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment