Skip to content

Instantly share code, notes, and snippets.

@norcross
Created October 1, 2012 15:38
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save norcross/3812565 to your computer and use it in GitHub Desktop.
Save norcross/3812565 to your computer and use it in GitHub Desktop.
embed gist shortcode
/* Optional CSS for themes that don't wrap the pre tag properly */
div.github-gist-block pre {
background-color: #F5F5F5;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px 4px 4px 4px;
display: block;
font-size: 13px;
line-height: 20px;
margin: 0 0 10px;
padding: 9.5px;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}
function gist_shortcode($atts, $content = NULL) {
extract( shortcode_atts( array(
'id' => '',
'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/'.$id.'.js"></script>';
$gist .= '</div>';
// now send it all back
return $gist;
}
add_shortcode ( 'gist', 'gist_shortcode');
/* USAGE
the ID is found in the URL of the gist. For example, this one is https://gist.github.com/gists/3812565/
[gist id="3812565"]
You can add an optional title to show up above the block
[gist id="3812565" title="My Gist Title"]
without the ID present, nothing will fire.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment