Skip to content

Instantly share code, notes, and snippets.

@johnregan3
Last active September 28, 2016 16:23
Show Gist options
  • Save johnregan3/5e9f51464abcbc0984dea4ec70ac02d1 to your computer and use it in GitHub Desktop.
Save johnregan3/5e9f51464abcbc0984dea4ec70ac02d1 to your computer and use it in GitHub Desktop.
Registering a Custom Template with the WP AMP plugin
<?php
/**
* Add a custom AMP template file.
*
* Registers templates in a templates subdirectory by post type slug.
* (e.g., "./templates/book.php")
*
* @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
*/
public function xwp_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';
}
return $file;
}
add_filter( 'amp_post_template_file', 'xwp_amp_custom_templates', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment