I am querying an advanced custom fields wysiwyg field. Problem is in the output wordpress wraps occasional imgs and iframes with p tags no matter what i try. Deactivate the wpautop works remove_filter ('acf_the_content', 'wpautop');
but if i try to exclude only imgs and iframes with the following snippet it fails:
function 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('the_content', 'filter_ptags_on_images');
Does anyone have a suggestion how to accomplish that goal? Best regards Ralf