Skip to content

Instantly share code, notes, and snippets.

@norcross
Last active December 12, 2015 08:08
Show Gist options
  • Save norcross/4741225 to your computer and use it in GitHub Desktop.
Save norcross/4741225 to your computer and use it in GitHub Desktop.
embed Gist shortcode
<?php
// usage: get the gist ID and place the shortcode in the site: [gist id="THE_ID"]
// allows for an optional title to display above, i.e [gist id="THE_ID" title="Some Title"]
// embed gists
function gist_shortcode($atts, $content = NULL) {
extract( shortcode_atts( array(
'id' => '',
'user' => 'norcross',
'title' => ''
), $atts ) );
if (empty ($id) )
return;
$gist = '<div class="github-gist-block">';
if(!empty($title))
$gist .= '<h4>'.$title.'</h4>';
$gist .= '<script src="https://gist.github.com/'.$user.'/'.$id.'.js"></script>';
$gist .= '</div>';
// now send it all back
return $gist;
}
add_shortcode ( 'gist', 'gist_shortcode');
@kopepasah
Copy link

Very useful.

The only thing I don't like about the script embed method is the inability to separate multiple files within one gist.

I also wish they allowed user defined styles. :)

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