Last active
September 28, 2016 16:23
-
-
Save johnregan3/5e9f51464abcbc0984dea4ec70ac02d1 to your computer and use it in GitHub Desktop.
Registering a Custom Template with the WP AMP plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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