Skip to content

Instantly share code, notes, and snippets.

@millipedia
Last active March 13, 2019 11:30
Show Gist options
  • Save millipedia/10017099 to your computer and use it in GitHub Desktop.
Save millipedia/10017099 to your computer and use it in GitHub Desktop.
CMS Made Simple User Defined Tag for embedding a Youtube video
// write out an embed tag for a youtube vid.
$ytCode=$params['code'];
if(isset($params['height'])){
$height=$params['height'];
}else{
$height=290;
}
if(isset($params['width'])){
$width=$params['width'];
}else{
$width=560;
}
if(isset($params['autoplay'])){
$autoplay=$params['autoplay'];
}else{
$autoplay=0;
}
$vidString='<div class="embed-responsive embed-responsive-16by9">';
$vidString.='<iframe width="'.$width.'" height="'. $height .'" src="https://www.youtube.com/embed/' . $ytCode .'?rel=0&modestbranding=1&showinfo=0" frameborder="0" allowfullscreen></iframe>';
$vidString.='</div>';
echo $vidString;
@millipedia
Copy link
Author

If you're using Bootstrap then the tag has the correct classnames for responsive videos or you can use these css classes.

// Embeds responsive
//
// Credit: Nicolas Gallagher and SUIT CSS.

.embed-responsive {
  position: relative;
  display: block;
  height: 0;
  padding: 0;
  overflow: hidden;

  .embed-responsive-item,
  iframe,
  embed,
  object,
  video {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 100%;
    border: 0;
  }
}

// Modifier class for 16:9 aspect ratio
.embed-responsive-16by9 {
  padding-bottom: 56.25%;
}

// Modifier class for 4:3 aspect ratio
.embed-responsive-4by3 {
  padding-bottom: 75%;
}

@millipedia
Copy link
Author

millipedia commented Mar 13, 2019

There is now a plugin version of this UDT over at https://github.com/millipedia/CMSMS_plugins - you should probably use that instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment