Skip to content

Instantly share code, notes, and snippets.

@levantoan
Last active October 17, 2015 16:40
Show Gist options
  • Save levantoan/fae35ed5bf667d968a68 to your computer and use it in GitHub Desktop.
Save levantoan/fae35ed5bf667d968a68 to your computer and use it in GitHub Desktop.
Add gist to wordpress. single and multi file
<?php
//add shortoce gist to wordpress
//Use [gist id="" file=""]
/*
EX: https://gist.github.com/fae35ed5bf667d968a68#file-shortcode-gist-php
=> shortcode: [gist id="fae35ed5bf667d968a68" file="ShortCode-Gist.php"]
*/
function gist_func( $atts ){
$atts = shortcode_atts( array(
'id' => '',
'file' => ''
), $atts, 'gist' );
if($atts['id']){
$file = ($atts["file"]) ? '?file='.$atts["file"] : '';
return '<script src="https://gist.github.com/'.$atts['id'].'.js'.$file.'"></script>';
}else{
return false;
}
}
add_shortcode('gist','gist_func');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment