Skip to content

Instantly share code, notes, and snippets.

@SanjeevMohindra
Created May 27, 2018 07:47
Show Gist options
  • Save SanjeevMohindra/8f02b92dde85e0fc22eaefdb18ec8c16 to your computer and use it in GitHub Desktop.
Save SanjeevMohindra/8f02b92dde85e0fc22eaefdb18ec8c16 to your computer and use it in GitHub Desktop.
Convert shortcode to AMP compatible Shortcode
<?php
// Do not copy the above php tag in your function.php
/**
* Change shortcodes to AMP compatible Shortcodes
*
* Add this to your function.php
*
* @author MetaBlogue
* @license GPL-2.0+
* @link https://metablogue.com/configure-enable-amp-wordpress/
*/
add_shortcode('gist-amp', 'jetpack_gist_amp_conversion');
function jetpack_gist_amp_conversion( $atts, $content = NULL ) {
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
$amp_gist_string = '<amp-gist layout="fixed-height" height="225" data-gistid="' .$content. '">' . '</amp-gist><br />';
return $amp_gist_string;
} else {
return do_shortcode('[gist]' .$content .'[/gist]');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment