Skip to content

Instantly share code, notes, and snippets.

@kirandash
Created July 29, 2016 07:42
Show Gist options
  • Save kirandash/517490369cb58d05266ab952470c275e to your computer and use it in GitHub Desktop.
Save kirandash/517490369cb58d05266ab952470c275e to your computer and use it in GitHub Desktop.
In case you want to have <img> in your content but not have them get "Auto P'd" like WordPress likes to do.
<?php
/* Filter p tags with images */
function kd_filter_ptags_on_images($content) {
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
return preg_replace('/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
}
add_filter('acf_the_content', 'kd_filter_ptags_on_images');
add_filter('the_content', 'kd_filter_ptags_on_images');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment