Last active
April 22, 2021 02:09
-
-
Save Crunchify/1fad3e32630de777dd0d2183ae41e80f to your computer and use it in GitHub Desktop.
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 | |
/** | |
* | |
* 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