github_gist_shortcode

Callback for gist shortcode.

Description

github_gist_shortcode( $atts, (string) $content = '' ); 

Parameters (2)

0. $atts
The atts.
1. $content — Optional. (string) => ''
The content.

Usage

  1. if ( !function_exists( 'github_gist_shortcode' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/shortcodes/gist.php'; 
  3.  
  4. // The atts. 
  5. $atts = null; 
  6.  
  7. // The content. 
  8. $content = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = github_gist_shortcode($atts, $content); 
  12.  

Defined (1)

The function is defined in the following location(s).

/modules/shortcodes/gist.php  
  1. function github_gist_shortcode( $atts, $content = '' ) { 
  2.  
  3. if ( empty( $atts[0] ) && empty( $content ) ) 
  4. return '<!-- Missing Gist ID -->'; 
  5.  
  6. $id = ( ! empty( $content ) ) ? $content : $atts[0]; 
  7.  
  8. // Parse a URL 
  9. if ( ! is_numeric( $id ) ) 
  10. $id = preg_replace( '#https?://gist.github.com/([a-zA-Z0-9]+)#', '$1', $id ); 
  11.  
  12. if ( ! $id ) 
  13. return '<!-- Invalid Gist ID -->'; 
  14.  
  15. $embed_url = "https://gist.github.com/{$id}.js"; 
  16.  
  17. if ( ! empty( $atts['file'] ) ) 
  18. $embed_url = add_query_arg( 'file', urlencode( $atts['file'] ), $embed_url ); 
  19. // inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables 
  20. return '<style>.gist table { margin-bottom: 0; }</style>' . '<script src="' . esc_url( $embed_url ) . '"></script>';