How to make an exception for a template not to load on AMP in wordpress?

79 Views Asked by At

I have my web page full on AMP using too the oficial plugin. I use templates for my content, the template is used everytime someone makes a post. All the page is in AMP but if I want that just one template just do not load in AMP, how can I make that happen? I tried using functions.php with no success

1

There are 1 best solutions below

0
la_petite_kozel On

You can achieve that by using amp_is_request in your template.

if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
   /* AMP Request */
} else {
   /* non AMP Request */
}

Otherwise you can use amp_skip_post filter in your functions.php:

add_action(
    'wp',
    function() {
        $template_slug = get_page_template_slug($post_id);
        if ( $template_slug == 'Your template slug' ) {
            add_filter( 'amp_skip_post', '__return_true' );
        }
    }
);

Note that both solutions will load full page in non AMP mode. If you want to load one of components in non AMP you can try using Sanitizers but still, that page is going to be AMP.