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', '123', $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
Ok if you want to strip the p tags for img’s and iframe’s for advanced custom fields you have to exchange
the_content
withacf_the_content
. The code looks that way: