addCode2Page: youTube embed snip

Post Reply
arfa
Master Bludit
Posts: 158
Joined: Tue Jul 04, 2017 4:31 am
Location: New Zealand
Has thanked: 13 times
Been thanked: 27 times

This segues from doobs Q on pages. I read the docs on custom fields more closely and saw the use of a youTube embed - but... it is just another plugin. There are 2 or 3 other youTube d'loads on the plugins page. One of the things I like about Bludit is its simplicity and too many plugins nibbles into that for me.

So, I set too and here is a snippet for my
https://plugins.bludit.com/plugin/addcode2page
plugin.

It allows iframe sizing and is responsive.

Code: Select all

<?php
// NB aspect-ratio was introduced in 2021 so should be reasonably browser compatible
// unless the ratio needs changing all you need to do is consider the .wrap width and
// paste in the embed code from the youTube video [this is the iframe section]

$snipData .= '<style> .video { aspect-ratio: 16/9;}  .video > *  { width: 100%; height: 100%; } 
              .wrap { max-width: 444px; }  // CHANGE WIDTH:  size or units    
       </style>';
$snipData .= '<div class="wrap"><div class="video">';

// PASTE EMBEDDED IFRAME CODE HERE
$snipData .= '<iframe width="560" height="315" src="https://www.youtube.com/embed/NAf3UCCXugU?si=aInQKcEtRXVWHtgz" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>';

$snipData .= '</div></div>';
 ?>
Post Reply