Skip to content

Instantly share code, notes, and snippets.

@dyama
Forked from kachi/gist:2053869
Last active December 26, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyama/7103855 to your computer and use it in GitHub Desktop.
Save dyama/7103855 to your computer and use it in GitHub Desktop.
<?php
// [gist id="ID" file="FILE"]
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');
// Remove this function if you don't want autoreplace gist links to shortcodes
function gist_shortcode_filter($content) {
return preg_replace('/https:\/\/gist.github.com\/([\da-f]+)[\.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