amp_post_template_file doesn’t work
-
I’m developing in localhost an AMP version for a live website.
Only one thing is not working well. The custom template for the homepage is not called.
I did these steps:[x] Add
add_theme_support( 'amp', array( 'template_dir' => 'amp-templates', ) );to myfunctions.php;
[x] Check all boxes in AMP Settings;
[x] Go to Pages, EDIT my Homepage and ENABLE AMP;
[x] Add the code below in myfunctions.phpfunction xyz_filter_home_and_blog_amp_post_template( $template, $template_type, $post ) { if ( 'page' === $template_type && 'page' === get_option( 'show_on_front' ) ) { if ( (int) get_option( 'page_on_front' ) === $post->ID ) { $template = dirname( __FILE__ ) . '/amp-templates/front-page.php'; } elseif ( (int) get_option( 'page_for_posts' ) === $post->ID ) { $template = dirname( __FILE__ ) . '/amp-templates/blog.php'; } } return $template; } add_filter( 'amp_post_template_file', 'xyz_filter_home_and_blog_amp_post_template', 10, 3 );But when I access http://localhost/mysite/?amp (my homepage), the main file
front-page.phpinside the template root is still called.Curiously, the AMP is working on this page, because the files header.php and footer.php inside the root template directory is calling AMP code.
All the other templates/custom templates are working fine.
In addition to creating the filetheme-root/amp-templates/front-page.phpI created the filetheme-root/amp-templates/index.phpand still not working.I tested with these 2 files and WITHOT the filter
amp_post_template_fileand still no working.Another curious thing is: I put this
ECHOin the function:function xyz_filter_home_and_blog_amp_post_template( $template, $template_type, $post ) { echo "CALLED!";exit; if ( 'page' === $template_type && 'page' === get_option( 'show_on_front' ) ) { ..... } add_filter( 'amp_post_template_file', 'xyz_filter_home_and_blog_amp_post_template', 10, 3 );If this filter was triggered, the page have to break and prints only the word: CALLED
But, after insert thisechoand reload the homepage, the page loads regular. In other words, the filter is not triggered.Someone knows what I’m doing wrong?
Tks!
The topic ‘amp_post_template_file doesn’t work’ is closed to new replies.