wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Remove p tag from around images in the_content

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will remove the HTML p tag from around images in the_content.

snippet :  PHPcopy
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');
source →

Did you like this post? If so please share it with your friends. Thanks!