Using this snippet, your image will not be contained within a <p> tag. So, instead of <p class=”xy”><img src=””>, your img will be embedded in the <img> Tag only. This might be helpful for page builders, like Divi, or Elementor.
To use this, add this function to your functions.php or via a Code Snippet Plugin.
// Remove <p> tags around images
function filter_ptags_on_images($content) {
return preg_replace('/ (\s*)()(\s*)<\/p>/iU', '\2', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
Leave a Reply