The code I'm using works, but I'm a newbie, does this code have any errors, wrong syntax, or redundant code?
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
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;
}
// Whitelist query vars
add_filter( "query_vars", "my_query_vars" );
function my_query_vars( $vars ) {
$vars[] = AMP_QUERY_VAR;
return $vars;
}
function custom_rewrite_rule() {
add_rewrite_rule('^'. AMP_QUERY_VAR .'/([^/]*)/?','index.php?'.
AMP_QUERY_VAR .'=1&name=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0 );