Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Add custom AMP template files.
*
* 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 && ( 'book' === $post->post_type ) ) {
$file = dirname( __FILE__ ) . '/templates/book.php';
} elseif ( '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