Totally Random Musings from the Edge

Embedding YouTube Videos in Jekyll Sites

21 July 2017

This article will take Less than 1 minute to read

If you’re embedding YouTube videos on your Jekyll site it can be a pain in the butt to include the YouTube embed code every time. Here is an easy way to use includes instead of using a plugin.

Create a file in your _includes folder called youtubePlayer.html with this content:

<iframe width="640" height="385" src="https://www.youtube.com/embed/{{ include.id }}" frameborder="0" allowfullscreen></iframe>

Then include this snippet whenever you want to embed a YouTube video:

{% include youtubePlayer.html id="youtubeId" %}

Don’t forget to replace youtubeId with the actual ID of the video.

Related Posts