Skip to content

Instantly share code, notes, and snippets.

@benbalter
Last active October 15, 2024 15:32
Show Gist options
  • Save benbalter/5555251 to your computer and use it in GitHub Desktop.
Save benbalter/5555251 to your computer and use it in GitHub Desktop.
Example of how to embed a Gist on GitHub Pages using Jekyll.

Here's an example of how to embed a Gist on GitHub Pages:

{% gist 5555251 %}

All you need to do is copy and paste the Gist's ID from the URL (here 5555251), and add it to a gist tag surrounded by {% and %}.

And here's what it would look like rendered:

Rendered Gist

@alejobit
Copy link

alejobit commented Oct 28, 2016

It works by installing https://github.com/jekyll/jekyll-gist

But I prefer to use:

<script src="https://gist.github.com/benbalter/5555251.js"></script>
<script src="https://gist.github.com/benbalter/5555251.js?file=gist.md"></script>

@ogurcan
Copy link

ogurcan commented Mar 8, 2017

I tried to embed <script src="https://gist.github.com/benbalter/5555251.js"></script> and other examples in an .md file, however it doesnt work :(

@palevell
Copy link

palevell commented Oct 9, 2017

This didn't work for me . . .
Error: Liquid syntax error (line 3): Unknown tag 'gist'

But, using the Embed code from the gist page worked, just fine.

@weibeld
Copy link

weibeld commented Oct 29, 2017

Note that for this to work, you need to have the following in your Gemfile:

gem "github-pages", group: :jekyll_plugins

This installs, among others, the jekyll-gist gem which provides the {% gist %} tag. Without the jekyll-gist gem, Jekyll reports a Unknown tag 'gist' error when the site is built locally.

Of course, you could also have just gem "jekyll-gist" in your Gemfile, and the local build should work (and on GitHub Pages this gem is installed anyway). But if you're anyway deploying to GitHub Pages, it is much better to use the github-pages gem (which includes the jekyll-gist gem), as shown above, for the following reason:

The github-pages gem installs locally all the gems that are also installed on GitHub Pages, and the same versions of these gems. This ensures that your local build environment is the same as the build environment used on GitHub Pages. So, it is ensured that everything that works locally, will also work on GitHub Pages, and that the site will look the same on GitHub Pages as it looks on your local machine.

You basically don't need anything else than gem "github-pages", group: :jekyll_plugins in the Gemfile for best compatibility with GitHub Pages.

@arefaslani
Copy link

Is there any way to link a revision of a gist file?

@alithom123
Copy link

^^^ I want this feature also!!! I want to be abled to embed each revision of a gist.

@eloiseg274
Copy link

What are you talking about

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