Skip to content

Instantly share code, notes, and snippets.

@asmerkin
Last active February 19, 2019 19:30
Show Gist options
  • Save asmerkin/893e4bb0ecc6480cfd4b4f3ae668c45b to your computer and use it in GitHub Desktop.
Save asmerkin/893e4bb0ecc6480cfd4b4f3ae668c45b to your computer and use it in GitHub Desktop.
A Small wordpress shortcode for Gists.
<?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