Created
March 22, 2013 03:57
-
-
Save michaelmusgrove/5218857 to your computer and use it in GitHub Desktop.
Create a Shortcode in WordPress to display Gists by ID. (Example: [github-gist id="GIST-ID"])
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
add_shortcode('github-gist', 'pu_embed_gist'); | |
function pu_embed_gist($atts, $content = null) | |
{ | |
extract(shortcode_atts(array('id' => null), $atts)); | |
if( $id != null) | |
{ | |
$args = array('sslverify' => false); | |
$result = wp_remote_get('https://api.github.com/gists/' . $id, $args); | |
$json = json_decode($result['body'], true); | |
if(isset($json['description'])) | |
{ | |
$description = $json['description']; | |
if(isset($json['files']['gistfile1.txt']['content'])) | |
{ | |
$content = $json['files']['gistfile1.txt']['content']; | |
echo ' | |
<h2>'.$description.'</h2> | |
'; | |
echo ' | |
<pre><code>'; | |
echo $content; | |
echo '</code></pre> | |
'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment