Skip to content

Instantly share code, notes, and snippets.

@waqashassan98
Created February 17, 2019 20:38
Show Gist options
  • Save waqashassan98/c7461665de693083961dd51489831f1d to your computer and use it in GitHub Desktop.
Save waqashassan98/c7461665de693083961dd51489831f1d to your computer and use it in GitHub Desktop.
Load amp templates without plugin wordpress
define( 'AMP_QUERY_VAR', 'amp' );
add_rewrite_endpoint(AMP_QUERY_VAR , EP_PERMALINK | EP_PAGES | EP_ROOT);
add_filter( 'template_include', 'amp_page_template',99 );
function amp_page_template( $template ) {
if( get_query_var( AMP_QUERY_VAR , false ) !== false ) {
if ( is_page( 'about-us' ) ) {
$new_template = get_template_directory() . '/amp-about-us.php';
return $new_template;
}
if ( is_home() ) {
$new_template = get_template_directory() . '/amp-home.php';
return $new_template;
}
}
return $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment