Skip to content

Instantly share code, notes, and snippets.

@zinigor
Created October 28, 2015 14:40
Show Gist options
  • Save zinigor/48597632a5b53e63dea0 to your computer and use it in GitHub Desktop.
Save zinigor/48597632a5b53e63dea0 to your computer and use it in GitHub Desktop.
Github gist shortcode patch
diff --git a/modules/shortcodes/gist.php b/modules/shortcodes/gist.php
index 27e1f00..39ebd4d 100644
--- a/modules/shortcodes/gist.php
+++ b/modules/shortcodes/gist.php
@@ -30,23 +30,29 @@ function github_gist_shortcode( $atts, $content = '' ) {
if ( ! $id )
return '<!-- Invalid Gist ID -->';
- $embed_url = "{$id}.json";
+ if ( ! empty( $atts['file'] ) ) {
+ $file = '?file=' . urlencode( $atts['file'] );
+ } else {
+ $file = '';
+ }
- if ( ! empty( $atts['file'] ) )
- $embed_url .= '?file=' . urlencode( $atts['file'] );
+ $embed_url = "{$id}.json" . $file;
// inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables
$return = '<style>.gist table { margin-bottom: 0; }</style>' .
'<div class="gist-oembed" data-gist="' . esc_attr( $embed_url ) . '"></div>';
-
if ( isset( $_POST[ 'type' ]) && 'embed' === $_POST[ 'type' ] &&
isset( $_POST[ 'action' ] ) && 'parse-embed' === $_POST['action'] ) {
- ob_start();
- wp_print_scripts( 'jetpack-gist-embed' );
- $return .= ob_get_clean();
+ return github_gist_simple_embed( $id, $file );
}
return $return;
}
+
+function github_gist_simple_embed( $id, $file ) {
+ $embed_url = $id . '.js' . $file;
+
+ return '<script type="text/javascript" src="//gist.github.com/' . $embed_url . '"></script>';
+}
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment