Create a gist now

Instantly share code, notes, and snippets.

@vanto /
Last active Aug 7, 2017

What would you like to do?
OEmbed Liquid Tag for Jekyll

OEmbed Liquid Tag for Jekyll

This is a simple liquid tag that helps to easily embed images, videos or slides from OEmbed enabled providers. It uses Magnus Holm's great oembed gem which connects to the OEmbed endpoint of the link's provider and retrieves the HTML code to embed the content properly (i.e. an in-place YouTube player, Image tag for Flickr, in-place slideshare viewer etc.). By default it supports the following OEmbed providers (but can fallback to or OoEmbed for other providers):

  • Youtube
  • Flickr
  • Viddler
  • Qik
  • Revision3
  • Hulu
  • Vimeo
  • Instagram
  • Slideshare
  • Yfrog
  • MlgTv

How to install

  1. Make sure you have the ruby-oembed gem (Rubygems, Github) installed.
  2. Copy oembed.rb to <your-jekyll-project>/_plugins
  3. You're done.

If you're experiencing troubles with Ruby 2.x, please also add require 'openssl' to the script.

How to use

Place a oembed tag in your content file. E.g.

<h1>An embedded video</h1>
{{ oembed }}

<h1>An embedded presentation</h1>
{{ oembed }}

The oembed tag behaves almost compatible to Robert Böhnke's Tag, i.e. it wraps the embed code in a <div> tag that has classes matching the embeds type, provider as well as the generic embed. In contrast to the tag, we don't support overriding certain oembed properties.


Tammo van Lessen --


This code snippet is licensed under Apache License 2.0

# OEmbed Liquid Tag for Jekyll
# - requires
# Copyright 2011 Tammo van Lessen
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
require 'oembed'
require 'uri'
# register all default OEmbed providers
# since register_all does not register all default providers, we need to do this here. See
::OEmbed::Providers.register(::OEmbed::Providers::Instagram, ::OEmbed::Providers::Slideshare, ::OEmbed::Providers::Yfrog, ::OEmbed::Providers::MlgTv)
::OEmbed::Providers.register_fallback(::OEmbed::ProviderDiscovery, ::OEmbed::Providers::Embedly, ::OEmbed::Providers::OohEmbed)
module Jekyll
class OEmbed < Liquid::Tag
def initialize(tag_name, text, tokens)
@text = text
def render(context)
# pipe param through liquid to make additional replacements possible
url = Liquid::Template.parse(@text).render context
# oembed look up
result = ::OEmbed::Providers.get(url.strip!, :format => :xml)
# Odd: slideshare uses provider-name instead of provider_name
provider = result.fields['provider_name'] || result.fields['provider-name'] || 'unknown'
"<div class=\"embed #{result.type} #{provider}\">#{result.html}</div>"
Liquid::Template.register_tag('oembed', Jekyll::OEmbed)

harikt commented May 25, 2012

Hi ,
Does this works for github ? I have this at

and post

I guess we cannot install any other libraries in github. I am not familiar with ruby also .

Thanks for the help.


vanto commented May 25, 2012

AFAIK, github does not allow 3rd party plugins for its Jekyll based site generation, so you'd need to setup your own.

harikt commented May 25, 2012

yyolk commented Jun 8, 2012

I'm having a very hard time getting this to work.

My loop in my Jekyll Template:

        {% if page.oembed %}
            {% for url in page.oembed %}
                {{ oembed url }}
            {% endfor %} 
        {% endif %}

This doesn't produce what is supposed to happen… and I'm at a lost to why it is in the first place.


vanto commented Jun 8, 2012

If you want to use a variable, you need to use liquid again. Please try this:

{% if page.oembed %}
    {% for url in page.oembed %}
        {% oembed {{url}} %}
    {% endfor %} 
{% endif %}

yyolk commented Jun 8, 2012

You are my hero! That solved my issue!!

jmoz commented Apr 10, 2013

Is there a reason why this doesn't work with Twitter? Keep getting ::OEmbed::NotFound errors.

I followed your sample steps, and it works when I use ruby-1.9.3-p194. But it errors when using ruby-2.0.0-p0. Here's the stack trace:

dldunckel@work-dan:~/code/sandbox/oembed/$ jekyll --no-server
Configuration from /home/dldunckel/code/sandbox/oembed/
Building site: /home/dldunckel/code/sandbox/oembed/ -> /home/dldunckel/code/sandbox/oembed/
Liquid Exception: uninitialized constant OEmbed::Provider::OpenSSL in index.html
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/ruby-oembed-0.8.8/lib/oembed/provider.rb:132:in `raw'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/ruby-oembed-0.8.8/lib/oembed/provider.rb:85:in `get'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/ruby-oembed-0.8.8/lib/oembed/providers.rb:102:in `get'
/home/dldunckel/code/sandbox/oembed/ `render'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/liquid-2.5.0/lib/liquid/block.rb:106:in `block in render_all'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/liquid-2.5.0/lib/liquid/block.rb:93:in `each'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/liquid-2.5.0/lib/liquid/block.rb:93:in `render_all'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/liquid-2.5.0/lib/liquid/block.rb:82:in `render'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/liquid-2.5.0/lib/liquid/template.rb:124:in `render'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/liquid-2.5.0/lib/liquid/template.rb:132:in `render!'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/jekyll-0.12.1/lib/jekyll/convertible.rb:79:in `do_layout'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/jekyll-0.12.1/lib/jekyll/page.rb:100:in `render'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/jekyll-0.12.1/lib/jekyll/site.rb:204:in `block in render'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/jekyll-0.12.1/lib/jekyll/site.rb:203:in `each'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/jekyll-0.12.1/lib/jekyll/site.rb:203:in `render'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/jekyll-0.12.1/lib/jekyll/site.rb:41:in `process'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/gems/jekyll-0.12.1/bin/jekyll:264:in `<top (required)>'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/bin/jekyll:19:in `load'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/bin/jekyll:19:in `<main>'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/bin/ruby_noexec_wrapper:14:in `eval'
/home/dldunckel/.rvm/gems/ruby-2.0.0-p0@test-oembed/bin/ruby_noexec_wrapper:14:in `<main>'
Build Failed

Same here!

/Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oembed-0.8.8/lib/oembed/provider.rb:132:in `raw': uninitialized constant OEmbed::Provider::OpenSSL (NameError)
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oembed-0.8.8/lib/oembed/provider.rb:85:in `get'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oembed-0.8.8/lib/oembed/providers.rb:102:in `get'
from /Users/xnikp/Sites/blog/_plugins/oembed.rb:45:in `render'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/liquid-2.5.0/lib/liquid/block.rb:106:in `block in render_all'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/liquid-2.5.0/lib/liquid/block.rb:93:in `each'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/liquid-2.5.0/lib/liquid/block.rb:93:in `render_all'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/liquid-2.5.0/lib/liquid/block.rb:82:in `render'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/liquid-2.5.0/lib/liquid/template.rb:124:in `render'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/liquid-2.5.0/lib/liquid/template.rb:132:in `render!'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/convertible.rb:77:in `render_liquid'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/convertible.rb:125:in `do_layout'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/post.rb:263:in `render'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/site.rb:228:in `block in render'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/site.rb:227:in `each'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/site.rb:227:in `render'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/site.rb:44:in `process'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/command.rb:18:in `process_site'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/commands/build.rb:23:in `build'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/lib/jekyll/commands/build.rb:7:in `process'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/jekyll-1.0.3/bin/jekyll:85:in `block (2 levels) in <top (required)>'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/commander-4.1.3/lib/commander/command.rb:180:in `call'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/commander-4.1.3/lib/commander/command.rb:180:in `call'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/commander-4.1.3/lib/commander/command.rb:155:in `run'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/commander-4.1.3/lib/commander/runner.rb:402:in `run_active_command'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/commander-4.1.3/lib/commander/runner.rb:78:in `run!'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/commander-4.1.3/lib/commander/delegates.rb:7:in `run!'
from /Users/xnikp/.rvm/gems/ruby-2.0.0-p247/gems/commander-4.1.3/lib/commander/import.rb:10:in `block in <top (required)>'

alx commented Jul 21, 2013

After a problem, I noticed that ruby-oembed gem must be installed, and not oembed (that one should be removed if you've installed it)

the example oembed calls above are wrong. as the plugin is a liquid tag and not a filter, you have to embed content with the call

`{% oembed %}``

@vanto: please update the examples above also with the correct gem dependency: gem install ruby-oembed

Add Soundcloud Provider:

Those with Ruby 2.x problems, you would need to require 'openssl' first.


vanto commented Feb 28, 2014

@snrbrnjna, @benjamintanweihao Thanks for the hints, I updated the readme accordingly.

it doens't seem to work with vimeo anymore
no error or console output or anything...

I created a version that also supports optional width/height dimension parameters:

I had to add require 'net/https', as per judofyr/ruby-oembed#31
(error: undefined methoduse_ssl='`)

Can somebody help me. How can i display youtube video in size 1000px?
Whit this code i get only 480px width:
{% oembed %}

gemfarmer commented Feb 22, 2017

@dragysin79 I just created an updated version of this plugin that you can see here:

It supports width, height, title

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