Last active
February 19, 2019 19:30
-
-
Save asmerkin/893e4bb0ecc6480cfd4b4f3ae668c45b to your computer and use it in GitHub Desktop.
A Small wordpress shortcode for Gists.
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 | |
/* | |
* To use this shortcode you must add the gist url and a file if you want | |
* | |
* [gist url="https://gist.github.com/....." file="example.file"] | |
* | |
* You can omit the file to show all files together | |
*/ | |
class Gist { | |
public function __construct() { | |
add_shortcode( 'gist', array($this, 'shortcode') ); | |
} | |
public function shortcode( $attributes ) | |
{ | |
$values = shortcode_atts([ | |
'url' => '', | |
'file' => '' | |
], $attributes); | |
// Returning Empty if the url is Empty. | |
if($values['url'] == '') { return ''; } | |
$output = '<script src="'. $values['url'] . '.js'; | |
if($values['file'] != '') | |
{ | |
$output .= '?file=' . $values['file']; | |
} | |
$output .= '"></script>'; | |
return $output; | |
} | |
} | |
new Gist(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment