troubleshooting Question

I'm using a filter to remove p tags from around images in the Content in WordPress, but it's not working

Avatar of Alicia St Rose
Alicia St RoseFlag for United States of America asked on
WordPress* Advanced Custom Fields
13 Comments1 Solution195 ViewsLast Modified:
I'm using a plugin called Advanced Custom fields and I'm not able to remove the p tags even though I've found this filter everywhere, including the ACF forum.

//filter the <p> tags from the images and iFrame
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('acf_the_content', 'filter_ptags_on_images');
add_filter('the_content', 'filter_ptags_on_images');

Any one have a situation like this? Not sure why it isn't working even though I've used it before!
Alicia St Rose
WordPress Dev & WordPress Coach

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros