Skip to content

Instantly share code, notes, and snippets.

@danielmcclure
Created December 11, 2018 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmcclure/67bdf0580bc09540ece1598af7464251 to your computer and use it in GitHub Desktop.
Save danielmcclure/67bdf0580bc09540ece1598af7464251 to your computer and use it in GitHub Desktop.
Enable & Customise AMP Compatibility Within WordPress Themes
<?php
// Enabled Paired Mode (Recommended)
add_theme_support( 'amp', array(
'paired' => true,
) );
// Enabled Native Mode (Less Functional)
add_theme_support( 'amp', array(
'paired' => false, // Force native mode
) );
// Specify Custom Template Directory
add_theme_support( 'amp', array(
'template_dir' => 'amp-templates',
) );
// Enable AMP Templates universally
add_theme_support( 'amp', array(
'templates_supported' => 'all',
) );
// Selectively enable AMP Template Support
add_theme_support( 'amp', array)
'templates_supported' => array(
'is_singilar' => true,
'os_search' => false,
),
) );
/*
* NOTE: When using paired mode, use the `is_amp_endpoint` conditional to specificy AMP specific functionality
*
<?php if ( is_amp_endpoint() ) : ?>
on="tap:AMP.setState( { siteNavigationMenuExpanded: ! siteNavigationMenuExpanded } )"
[aria-expanded]="siteNavigationMenuExpanded ? 'true' : 'false'"
<?php endif; ?>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment