0

The below code is working for all pages and posts but it is not working for front page anybody helps me.

e.g HTML version www.example.com and AMP version www.example.com/amp

How to include amp template for the front page?

<?php
    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';

            } 

        }

        return $template;
    } ?>
1

is_single() will return false for Pages, so the above code as written should only work for single Posts.

You'll need to add more conditionals to your amp_page_template() function for each of the templates you want to replace with an AMP version. Depending on your settings in Settings > Reading > Front page displays, is_front_page() might be what you're looking for, alternatively you could try is_home().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.