Skip to content

Instantly share code, notes, and snippets.

@jonathanfann
Last active October 21, 2016 14:03
Show Gist options
  • Save jonathanfann/ae707752f2f2c3f93e739838f8dce5c0 to your computer and use it in GitHub Desktop.
Save jonathanfann/ae707752f2f2c3f93e739838f8dce5c0 to your computer and use it in GitHub Desktop.
Wordpress Gist Shortcode
// 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> */
@jonathanfann
Copy link
Author

jonathanfann commented Oct 21, 2016

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment