Last active
December 12, 2015 08:08
-
-
Save norcross/4741225 to your computer and use it in GitHub Desktop.
embed Gist shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. :)