Support » Fixing WordPress » Remove Paragraph Tags From Around Videos

  • Hi,
    I found this article that shows how to remove p tags around images. I would like to do the same for video.

    The code for images is:

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

    I tried this:

    function filter_ptags_on_images($content){
       return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
    return preg_replace('/<p>\s*(<a .*>)?\s*(<video .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
    }
    
    add_filter('the_content', 'filter_ptags_on_images');

    But it doesn’t work.
    What is wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove Paragraph Tags From Around Videos’ is closed to new replies.