admin管理员组文章数量:1130349
Before you ask I have looked around the similar questions to find a resolution but I couldn't find one that worked.
- Ive tried the permalink option several times,
- There is nothing in my htaccess file that would be causing the 404
- There's no caching software installed
- There are no other plugins that im using for redirection or amp
- The is_single() works perfectly fine but the is_page() does not, i've also tried is_front_page(), is_category(), is_home(), is_page('specific page') but again dont seem to work.
- body_class() is included in the body tag.
So I'm really not sure why it isnt working, see code.
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_filter( 'template_include', 'amp_page_template', 99 );
function amp_page_template( $template ) {
if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {
if ( is_single() ) {
$template = get_template_directory() . '/amp-single.php';
}
if( is_page() ) {
$template = get_template_directory() . '/amp-page.php';
}
}
return $template;
}
Any answers would be greatly appreciated, cheers :)
Before you ask I have looked around the similar questions to find a resolution but I couldn't find one that worked.
- Ive tried the permalink option several times,
- There is nothing in my htaccess file that would be causing the 404
- There's no caching software installed
- There are no other plugins that im using for redirection or amp
- The is_single() works perfectly fine but the is_page() does not, i've also tried is_front_page(), is_category(), is_home(), is_page('specific page') but again dont seem to work.
- body_class() is included in the body tag.
So I'm really not sure why it isnt working, see code.
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_filter( 'template_include', 'amp_page_template', 99 );
function amp_page_template( $template ) {
if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {
if ( is_single() ) {
$template = get_template_directory() . '/amp-single.php';
}
if( is_page() ) {
$template = get_template_directory() . '/amp-page.php';
}
}
return $template;
}
Any answers would be greatly appreciated, cheers :)
Share Improve this question edited Oct 20, 2018 at 12:26 M0n5terBunny asked Oct 19, 2018 at 12:43 M0n5terBunnyM0n5terBunny 274 bronze badges 2- 1 What’s the problem exactly? You mention 404, templates have nothing to do with 404 errors. – Milo Commented Oct 19, 2018 at 12:50
- Im getting a 404, it's supposed to got to the amp-page.php page template. Like the single posts do when you goto the page then put /amp/ – M0n5terBunny Commented Oct 19, 2018 at 16:33
1 Answer
Reset to default 0Your endpoint is only applied to posts, add EP_PAGES to generate rules for page post type-
add_rewrite_endpoint( 'amp', EP_PERMALINK | EP_PAGES );
That should also be within a function hooked to init.
Before you ask I have looked around the similar questions to find a resolution but I couldn't find one that worked.
- Ive tried the permalink option several times,
- There is nothing in my htaccess file that would be causing the 404
- There's no caching software installed
- There are no other plugins that im using for redirection or amp
- The is_single() works perfectly fine but the is_page() does not, i've also tried is_front_page(), is_category(), is_home(), is_page('specific page') but again dont seem to work.
- body_class() is included in the body tag.
So I'm really not sure why it isnt working, see code.
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_filter( 'template_include', 'amp_page_template', 99 );
function amp_page_template( $template ) {
if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {
if ( is_single() ) {
$template = get_template_directory() . '/amp-single.php';
}
if( is_page() ) {
$template = get_template_directory() . '/amp-page.php';
}
}
return $template;
}
Any answers would be greatly appreciated, cheers :)
Before you ask I have looked around the similar questions to find a resolution but I couldn't find one that worked.
- Ive tried the permalink option several times,
- There is nothing in my htaccess file that would be causing the 404
- There's no caching software installed
- There are no other plugins that im using for redirection or amp
- The is_single() works perfectly fine but the is_page() does not, i've also tried is_front_page(), is_category(), is_home(), is_page('specific page') but again dont seem to work.
- body_class() is included in the body tag.
So I'm really not sure why it isnt working, see code.
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_filter( 'template_include', 'amp_page_template', 99 );
function amp_page_template( $template ) {
if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {
if ( is_single() ) {
$template = get_template_directory() . '/amp-single.php';
}
if( is_page() ) {
$template = get_template_directory() . '/amp-page.php';
}
}
return $template;
}
Any answers would be greatly appreciated, cheers :)
Share Improve this question edited Oct 20, 2018 at 12:26 M0n5terBunny asked Oct 19, 2018 at 12:43 M0n5terBunnyM0n5terBunny 274 bronze badges 2- 1 What’s the problem exactly? You mention 404, templates have nothing to do with 404 errors. – Milo Commented Oct 19, 2018 at 12:50
- Im getting a 404, it's supposed to got to the amp-page.php page template. Like the single posts do when you goto the page then put /amp/ – M0n5terBunny Commented Oct 19, 2018 at 16:33
1 Answer
Reset to default 0Your endpoint is only applied to posts, add EP_PAGES to generate rules for page post type-
add_rewrite_endpoint( 'amp', EP_PERMALINK | EP_PAGES );
That should also be within a function hooked to init.
本文标签: template includeWhy isn39t templateinclude working with AMP correctly
版权声明:本文标题:template include - Why isn't template_include working with AMP correctly? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749247265a2339095.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论