Skip to content

Instantly share code, notes, and snippets.

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 johnregan3/e713437b5cbf449af9a35c16890da00f to your computer and use it in GitHub Desktop.
Save johnregan3/e713437b5cbf449af9a35c16890da00f to your computer and use it in GitHub Desktop.
<?php
/**
* Add a custom AMP template file.
*
* Registers templates in a /templates subdirectory.
*
* @filter amp_post_template_file
*
* @param string $file The file name input.
* @param string $type The type of template.
* @param object $post WP Post Object.
*
* @return string
*/
function jr3_amp_custom_templates( $file, $type, $post ) {
if ( 'single' === $type ) {
$file = dirname( __FILE__ ) . '/templates/single.php';
} elseif ( 'style' === $type ) {
$file = dirname( __FILE__ ) . '/templates/style.php';
}
return $file;
}
add_filter( 'amp_post_template_file', 'jr3_amp_custom_templates', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment