Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crunchify/1fad3e32630de777dd0d2183ae41e80f to your computer and use it in GitHub Desktop.
Save Crunchify/1fad3e32630de777dd0d2183ae41e80f to your computer and use it in GitHub Desktop.
<?php
/**
*
* Example: https://gist.github.com/Crunchify/1fad3e32630de777dd0d2183ae41e80f
* Usage:
* [gist]1fad3e32630de777dd0d2183ae41e80f[/gist]
* [gist id="1fad3e32630de777dd0d2183ae41e80f" /]
*
* If a gist has multiple files you can select one
* [gist id="1fad3e32630de777dd0d2183ae41e80f" file="file-name" /]
*/
function crunchify_add_gist_github_shortcode( $atts, $content = NULL ) {
extract( shortcode_atts( array(
'id' => '',
'file' => '',
), $atts ) );
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
return sprintf('<amp-gist data-gistid="%s" %s layout="fixed-height" height="250"></amp-gist>',
$id ? $id : trim(esc_attr($content)),
$file ? 'data-file="' . esc_attr( $file ) . '"' : ''
);
} else {
return sprintf('<script src="https://gist.github.com/%s.js%s"></script>',
$id ? $id : trim(esc_attr($content)) ,
$file ? '?file=' . esc_attr( $file ) : ''
);
}
}
add_shortcode('gist', 'crunchify_add_gist_github_shortcode');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment