Created
April 20, 2015 12:17
-
-
Save azappella/87152d3e33fc23e0d3d9 to your computer and use it in GitHub Desktop.
Remove wordpress text editor added p tags around img elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Source: https://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment