Embed youtube iframe

Hello,

i use this code to embed a youtube video:

template:

 <!--//////-->
 <!--VIDEO-->
 <!--//////-->


    <?php
      if($article->video_url() != "")
      {
    ?>
        <iframe src="https://www.youtube.com/embed/<?php  echo $article->video_url(); ?>"  allowfullscreen></iframe>

    <?php
     }
    ?>

blueprint:

  video_url:
    label: Video
    type:  text

it’s the right way?

Well, if it works for you, why not? :wink:

PS: Please use backticks for code highlighting instead of normal apostrophes.

You can either use the iframe tag or the object tag to embed YouTube videos as explained here: https://developers.google.com/youtube/player_parameters?hl=en#Overview

1 Like

Thanks for the answers.

It works like that, but there’s a far easier way:

<?= youtube($article->video_url()) ?>

Works for vimeo as well, btw:

<?= vimeo($article->video_url()) ?>