duskosobic
1/25/2017 - 10:47 PM

Remove Paragraph Tags From Around Images. In case you want to have <img> in your content but not have them get "Auto P'd" like WordPress lik

Remove Paragraph Tags From Around Images. In case you want to have in your content but not have them get "Auto P'd" like WordPress likes to do.

<?php

function filter_ptags_on_images($content){
   return preg_replace('https://cdn.css-tricks.com/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}

add_filter('the_content', 'filter_ptags_on_images');

?>