ACF: Extra p tags added to oEmbed field output

[ad_1]

My website uses the Avada theme which includes a bundled version of ACF Pro and has ACF integrations built in. I have some pages that use an ACF repeater oEmbed subfield to add one or more Wistia videos into an Avada post cards element.

It works like I would expect, except the wistia script tag is getting wrapped in a p tag and therefore adding extra spacing above the video.

<p><script src=”https://fast.wistia.com/assets/external/E-v1.js” async></script></p>

WordPress does this with standard WYSIWYG editor oEmbeds and I was able to strip the extra p tags with the code at the very bottom of this post. But, for some reason, that code won’t remove the extra p tags from the ACF oEmbeds.

I found a few possible solution leads but can’t quite figure it out. I think the [acf/format\_value](https://www.advancedcustomfields.com/resources/acf-format_value/) filter might be key since it includes the oEmbed output rather than the field value (wistia url only). But that string doesn’t seem to include the p tags. So I’m guessing the p tags are being added when that string is added into the Avada post card text element. But then why doesn’t my code strip the p tags? Isn’t that part of the\_content?

I also tried adding the oEmbed via WYSIWYG subfield. It seems to do the same thing except it only adds a closing p tag for some reason (</p>) .

<script src=”https://fast.wistia.com/assets/external/E-v1.js” async></script></p>

**functions.php code to remove extra p tags and add wistia oEmbed**

function remove_ptags( $content ) {
$content = preg_replace(‘/<p>\s*(<(div|script|iframe).*>.*)\s*<\/p>/iU’, ‘$1’, $content);
return $content;
}
add_filter( ‘the_content’, ‘remove_ptags’ );

wp_oembed_add_provider( ‘/https?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/.*/’, ‘http://fast.wistia.com/oembed’, true);

[ad_2]
1 Comment
  1. What does the rest of the content look like? Is it block based? Or a plain text/ limited HTML?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer