Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AMP Snippets
<amp-addthis
width="auto"
height="68"
data-pub-id="{publisher_id}"
data-widget-id="{widget_id}"
data-widget-type="inline"
>
</amp-addthis>
<?php $page_name = sanitize_title( get_the_title() ); ?>
<amp-iframe
sandbox="allow-scripts allow-same-origin"
src="{analytics_url}?identifier=<?php echo esc_attr( $page_name ); ?>"
layout="fixed"
height="1"
width="1"
class="jsll-iframe"
>
<amp-img placeholder="" layout="fill" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"></amp-img>
</amp-iframe>
<?php $audio_file = get_field( 'audio_file' ); ?>
<amp-audio width="840" height="56" src="<?php echo esc_url( $audio_file ); ?>" class="ms-audio">
<div fallback>
<p><?php esc_html_e( 'Your browser doesn’t support HTML5 audio', 'microsoft' ); ?></p>
</div>
<source type="audio/mpeg" src="<?php echo esc_url( $audio_file ); ?>">
</amp-audio>
<?php
function wds_microsoft_amp_custom_head_scripts( $amp_template ) {
?>
<script async custom-element="amp-addthis" src="https://cdn.ampproject.org/v0/amp-addthis-0.1.js"></script>
<script async custom-element="amp-audio" src="https://cdn.ampproject.org/v0/amp-audio-0.1.js"></script>
<?php
}
add_action( 'amp_post_template_head', 'wds_microsoft_amp_custom_head_scripts' );
<?php
function wds_microsoft_amp_custom_template_scripts( $data ) {
/**
* This checks to see if amp-iframe is already in place.
* When an iframe is embedded into a post, it automatically adds amp-iframe.
* This creates an issue for us adding it in the head, as there could be multiple instances of amp-iframe which will throw a warning.
* This checks for amp-iframe first and if it's not already in place, adds it.
* Reference: https://wordpress.org/support/topic/amp-iframe-included-twice-it-will-be-an-error/#post-10758992
*/
if ( empty( $data['amp_component_scripts']['amp-iframe'] ) ) {
$data['amp_component_scripts']['amp-iframe'] = 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js';
}
return $data;
}
add_filter( 'amp_post_template_data', 'wds_microsoft_amp_custom_template_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.