Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-10-03 00:23:45

murnau
Member
From: Lower Saxony, Germany
Registered: 2022-10-23
Posts: 11

Embed Youtube

What is the easiest way to embed a youtube-video in an article?

Offline

#2 2024-10-03 02:30:19

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Embed Youtube

murnau wrote #337924:

What is the easiest way to embed a youtube-video in an article?

The easiest way is to copy paste their embed code. Having said that, it is incompatible with GTPR which requires a permission from your visitors before you serve any cookies. As such, Nicolas Morand’s oui cookie plugin comes to the rescue.

To respond to your question.

Create a miscellaneous form in Presentation>Forms, call it video, and add the following

<txp:oui_cookie name="video_cookie" duration="+1 month" values="yes" />
<txp:oui_if_cookie name="video_cookie">
<div class="embed-container">
<iframe width="100%" height="auto" id='m_<txp:yield name="media" />' src='https://www.youtube-nocookie.com/embed/<txp:yield name="media" />' frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div>
<txp:else />
<p class="accept"><a rel="nofollow noindex noodp noydir noarchive nocache" href="?m_<txp:yield name="media" />">Watch this youtube video here</a></p>
</txp:oui_if_cookie>

To embed the cookie warning in the article, and if accepted, the video itself use the id of the video. So if you wish to embed https://www.youtube.com/watch?v=4BtEakGuN8o, in the article page use:

<txp::video media="4BtEakGuN8o" />

for the CSS use

.embed-container{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;max-width:100%}
.embed-container embed,.embed-container iframe,.embed-container object{position:absolute;top:0;left:0;width:100%;height:100%}

Last edited by colak (2024-10-03 02:51:30)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2024-10-03 06:50:45

murnau
Member
From: Lower Saxony, Germany
Registered: 2022-10-23
Posts: 11

Re: Embed Youtube

Thank you for this detailed reply!

Offline

Board footer

Powered by FluxBB