Forked from johnregan3/wp-amp-tutorial-register-templates-style-cpts.php
Created
September 28, 2016 16:05
-
-
Save mihdan/af67eaa0f45a628d7b70c0b5e88f2475 to your computer and use it in GitHub Desktop.
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 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