Custom block youtube video

Hi.

I need help on how to embed youtube video on custom block with iframe (if it is possible making block attributes to paste youtube iframe code).

Thanks.

Hi Roxy,

Yes that’s possible. I did it this way:

image

Here an example of the iframe code:

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen loading="lazy" class="player youtube__iframe"</iframe>

If you want to share a video you can enable privacy mode. I did that and that why it is youtube-nocookie

On the src i removed the id of the video. Then with the block attribute you can let the client add it’s own id.

Guido

1 Like

Thanks Guido…it works… :slightly_smiling_face:

1 Like

Hi Roxy,

Great! Glad i could offer some help :slightly_smiling_face:

Another option, although not specifically an iFrame, is to use a custom function with wp_oembed_get() and pass the URL along as a variable. I do this with custom fields on a few sites and it works great.

image

1 Like

I did it with a inner block that only allows media embed. Then you can use default wordpress embed.