Automatically remove p tags on images in wordpress

Automatically remove p tags on images in wordpress

Simply paste the following code on your theme functions.php file, save it, and the <p> tags are gone.

function filter_ptags_on_images($content){
    return preg_replace('/<p>s*(<a .*>)?s*(<img .* />)s*(</a>)?s*</p>/iU', '123', $content);
}

add_filter('the_content', 'filter_ptags_on_images');

If you enjoyed this article, please consider sharing it!

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*