I am trying to wrap any iframe/embed in my content with some Facebook Instant Articles friendly code (only for that feed). I have it working, but it adds this code to oEmbed output as well which adds in a wrapper that is not needed (since the Facebook Instant Articles already handles oEmbed embeds).
Basically, how can I get the wrap on iframes/embeds to happen before the oEmbed stuff happens?
Below is the code I have:
function wrap_iframe( $content ) {
if (is_feed( INSTANT_ARTICLES_SLUG )) {
// Match any iframes or embeds
$pattern = '~<iframe.*</iframe>|<embed.*</embed>~';
preg_match_all( $pattern, $content, $matches );
foreach ( $matches[0] as $match ) {
$wrappedframe = '<figure class="op-interactive"><iframe>' . $match . '</iframe></figure>';
$content = str_replace($match, $wrappedframe, $content);
}
return $content;
}
}
add_filter( 'the_content', 'wrap_iframe' );