Home / functions.php / Remove p tag from around images in the_content
  • Remove p tag from around images in the_content

    remove-p-tag-from-around-images-in-the_content

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

    wordpress snippet : PHP

    <>
    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');
    

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, add_filter,

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks