Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2009 08:54
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save phatduckk/250722 to your computer and use it in GitHub Desktop.
Embed a Gist in Wordpress
Plugin Name: Gistson - Embedded Gist WP Plugin
Plugin URI:
Description: Use a shortcode [gist id="12345"] to embed A Gist from into your blog
Version: 0.1
Author: Arin Sarkissian
Author URI:
Copyright 2009 Arin Sarkissian
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Heavily based on Paul William's plugin:
Main difference is that this version doesn't do a JS, <script>, embed... the code from your gist is
actually in the HTML source.
Toss the gistson.php file into your blogs wp-content/plugins folder. Login to WP and enable the plugin.
Put this <LINK> tag in <HEAD> of header.php
<link rel="stylesheet" href=""/>
When you wanna embed a gist just type in:
[gist id=""]
[gist id="250709"]
You can exclude the attribution by doing this:
[gist id="250709" nometa="true"]
This is useful for when you have multiple gists. But for big chunks of code etc
I'd encourge you to keep the attribution cuz those guys have a business to run
function gist_shortcode_func($atts, $content = null) {
$url = '' . trim($atts['id']) . '.json';
$json = file_get_contents($url);
$assoc = json_decode($json, true);
if (isset($atts['nometa'])) {
// you'll end up with 2 1px borders at the bottom =(
$assoc['div'] = preg_replace('/<div class="gist\-meta">.*?(<\/div>)/is', '', $assoc['div']);
return $assoc['div'];
add_shortcode('gist', 'gist_shortcode_func');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment