Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnregan3/b72d71b86c6fdbc2ee245ed4aa36f4e4 to your computer and use it in GitHub Desktop.
Save johnregan3/b72d71b86c6fdbc2ee245ed4aa36f4e4 to your computer and use it in GitHub Desktop.
Registering Component Scripts for AMP Extensions with the WP AMP plugin
<?php
/**
* Include AMP component scripts.
*
* Be sure to only register the scripts for the extensions
* that you really need to reduce page load times.
*
* @filter amp_post_template_data
*
* @param array $data Input from filter.
*
* @return array
*/
public function xwp_amp_component_scripts( $data ) {
$custom_component_scripts = array(
'amp-sidebar' => 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js';
'amp-social-share' => 'https://cdn.ampproject.org/v0/amp-social-share-0.1.js';
'amp-carousel' => 'https://cdn.ampproject.org/v0/amp-carousel-0.1.js';
'amp-audio' => 'https://cdn.ampproject.org/v0/amp-audio-0.1.js';
'amp-brightcove' => 'https://cdn.ampproject.org/v0/amp-brightcove-0.1.js';
);
$data['component_scripts'] = array_merge( $data['component_scripts'], $custom_component_scripts );
return $data;
}
add_filter( 'amp_post_template_data', xwp_amp_component_scripts );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment