YouTube Video Embed

by Shane Robinson

This system ships with a custom YouTube Embed shortcode that makes it easy to embed as many videos in your markdown posts/pages as you like.

Features

  • Only requires the YouTube ID (with default fall back).
  • Allows you to set “Title” which is required for Accessibility (with default fall back to “YouTube Video”).
  • Allows you to set custom ratio to display older videos correctly (with default fall back to 16:9).
  • Allows you to set the clip start time in “mm:ss” format (optional).

Usage

Find the YouTube video you want to embed and grab the video ID. In the following example the video ID is oHg5SJYRHA0.

https://www.youtube.com/watch?v=oHg5SJYRHA0

We put the video ID in the first attribute.

Title in the second.

Also, in this particular example, the video is older and is not in the 16:9 format ratio. So we’ll take advantage of setting a custom ratio in the last attribute. I arrived at “8:6” by checking the size of the video’s embed, which is 1217 x 913, which divides to 1.33…as does 8/6.

And we can leave the fourth attribure, start time completely off because we want the video to start at the beginning. If we wanted it to start at 1:30 we would simple put “1:30” in the third attribute.

NOTE: If you want the video to display at regular 16:9 ratio and start at the beginning, you don’t even need to provide the empty third and fouth attributes. And if you just wanted the accessible Title to be the default “YouTube Video”, you wouldn’t even need the second attribute.

{% youtube "oHg5SJYRHA0", "Fun Title Here", "8:6" %}