Support » Plugin: oEmbed Gist » AMP (Google Accelerated Mobile Pages) Integration

  • Workaround to make plugin work with Amp
    File to be modified:

    plugins/oembed-gist/oembed-gist.php
    

    Search for Code

    if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
    	return sprintf( __( '<a href="%s">See the gist on github</a>.', 'oembed-gist' ), esc_url( $url ) );
    
    }

    and Replace with

    if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
    	if (!empty($p['id']) && !empty($p['file'])){ //@am changes to make this working with AMP Plugin
    		$gid = $p['id'];
    		$gfile = $p['file'];
    		return'<amp-gist data-gistid="'.$gid.'"
    				data-file="'.$gfile.'"
    				layout="fixed-height"
    				 height="197">
    				</amp-gist>';
    	}else{
    		return sprintf( __( '<a href="%s">See the gist on github</a>.', 'oembed-gist' ), esc_url( $url ) );
    	}
    }

    Note this works if you are adding Shortcode in this format

    [gist id="1231e04bc25e66a77c5487d4cdb65e4r3" file="xyz-file"]

    Note You need to add

    <script async custom-element="amp-gist" src="https://cdn.ampproject.org/v0/amp-gist-0.1.js"></script>
    in theme header

    For details visit amp doc
    https://amp.dev/documentation/examples/components/amp-gist/

  • You must be logged in to reply to this topic.