This solution utilises the ability to pass parameters to included files. You can pass the video ID to a generic YouTube embed code used on all pages.

Create file _includes/youtube.html containing the following code:

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/{{ include.id }}?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>

Note: this uses the “privacy enhanced mode” and only the YouTube video ID has been parametrised.

To embed a Youtube video, use this in your posts:

{% include youtube.html id="_G790yZA5CA" %}

Why bother?

For maintenance purposes, you want to be able to modify and/or update the HTML snippet used for all YouTube videos.

I prefer not to add tons of custom code to Jekyll even though there are several Jekyll YouTube plugins out there. To me this is an easier solution that requires zero plugins. Due to its simplicity, this method can easily be repurposed for other embeds such as Vimeo.

Improvements

This snippet does not take into account videos with different aspect ratios. In that case, you may want to extend the code a bit.


Sources