Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jekyll YouTube Embed Plugin

This is a plugin meant for Jekyll.

Example use:

Easily embed a YouTube video. Just drop this file in your _plugins directory.

{% youtube oHg5SJYRHA0 %}

You can also specify a height and width. If you do not, it defaults to 560 x 420.

{% youtube oHg5SJYRHA0 500 400 %}
class YouTube < Liquid::Tag
Syntax = /^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?/
def initialize(tagName, markup, tokens)
super
if markup =~ Syntax then
@id = $1
if $2.nil? then
@width = 560
@height = 420
else
@width = $2.to_i
@height = $3.to_i
end
else
raise "No YouTube ID provided in the \"youtube\" tag"
end
end
def render(context)
# "<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"http://www.youtube.com/embed/#{@id}\" frameborder=\"0\"allowfullscreen></iframe>"
"<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"http://www.youtube.com/embed/#{@id}?color=white&theme=light\"></iframe>"
end
Liquid::Template.register_tag "youtube", self
end
@dqvist
Copy link

dqvist commented Feb 6, 2019

It should be https src for the generated iframe code.
E.g.:
"<iframe width="#{@width}" height="#{@height}" src="https://www.youtube.com/embed/#{@id}?color=white&theme=light\"></iframe>"

@jeffreytse
Copy link

jeffreytse commented May 7, 2020

jekyll-spaceship - 🚀 A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, mermail, emoji, youtube, vimeo, dailymotion, etc.

Github: https://github.com/jeffreytse/jekyll-spaceship

jekyll-spaceship-demo

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