Add class and change src type inside wp_oembed_get

So I don't know how to properly do this and I've already spent like 3+ hours attempting to figure this out, so I'm getting help from the community.

What I'm trying to achieve:

  • Add class='optanon-category-C0002' and change the src to data-src in the iFrame that wordpress builds up.

Here is what I have:

public function get_modal()
{
    $config = [
        'content' = 'pThe video is currently unavailable./p',
    ];
    $video_link = '';
    if ($video = $this-get_video()) {
        foreach ($this-get_video()-get_sources() as $each_video) {
            $video_link .= $each_video-src;
        }
        $config['id'] = 'id-' . spl_object_hash($video);
        if (strpos($video_link, 'youtube')) {
            $config['content'] = wp_oembed_get($video_link, [
                'width' = 640,
                'height' = 480
            ]);
        }
    }

    return new Modal($config);
}

wp_oembed_get builds up a whole iFrame based on the link provided, such as this:

iframe title=Jason Kidd, Jalen Brunson amp; Josh Green React to Dallas Mavs 50th Win, Luka's Insane Pass to Doe width=640 height=360 src=https://www.youtube.com/embed/OvLkjtcxIA8?feature=oembed frameborder=0 allow=accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture allowfullscreen=/iframe

There are various filters such as oembed_dataparse and oembed_result, but I was not successful in altering the iFrame at all, so all help will be appreciated!

Topic embed oembed Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.