Created
February 4, 2012 16:29
-
-
Save Idered/1738812 to your computer and use it in GitHub Desktop.
Gist shortcode for Wordpress
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 | |
function gist_shortcode($atts) { | |
return sprintf( | |
'<script src="https://gist.github.com/%s.js%s"></script>', | |
$atts['id'], | |
$atts['file'] ? '?file=' . $atts['file'] : '' | |
); | |
} add_shortcode('gist','gist_shortcode'); | |
function gist_shortcode_filter($content) { | |
return preg_replace('/https:\/\/gist.github.com\/([\d]+)[\.js\?]*[\#]*file[=|_]+([\w\.]+)(?![^<]*<\/a>)/i', '[gist id="${1}" file="${2}"]', $content ); | |
} add_filter( 'the_content', 'gist_shortcode_filter', 9); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice. Many thx for the share