Last active
October 21, 2016 14:03
-
-
Save jonathanfann/ae707752f2f2c3f93e739838f8dce5c0 to your computer and use it in GitHub Desktop.
Wordpress Gist Shortcode
This file contains hidden or 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 to your functions.php | |
function gist_shortcode( $atts ) { | |
// Attributes | |
$atts = shortcode_atts( | |
array( | |
'name' => 'jonathanfann', | |
'slug' => 'ae707752f2f2c3f93e739838f8dce5c0', | |
), | |
$atts, | |
'gist' | |
); | |
// start output | |
$o = ''; | |
// append url | |
$o .= '<script src="https://gist.github.com/'; | |
// append name | |
$o .= $atts['name'] . '/'; | |
// append slug | |
$o .= $atts['slug'] . '.js"></script>'; | |
// return output | |
return $o; | |
} | |
add_shortcode( 'gist', 'gist_shortcode' ); | |
/* use the shortcode by entering [gist name="yourname" slug="yourslug"] to return | |
<script src="https://gist.github.com/yourname/yourslug.js"></script> */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the shortcode by entering [gist name="yourname" slug="yourslug"] in a wordpress post to return
<script src="https://gist.github.com/yourname/yourslug.js"></script>.
By default it will return:
'name' => 'jonathanfann',
'slug' => 'ae707752f2f2c3f93e739838f8dce5c0',
(https://gist.github.com/jonathanfann/ae707752f2f2c3f93e739838f8dce5c0)