function ttnews_amp_load() { if (get_query_var('ttnews_amp') == 1) { $amp_url = home_url('/' . get_query_var('ttnews_path') . '.html'); $post_id = url_to_postid($amp_url); if ($post_id) { global $wp_query; $post = get_post($post_id); $wp_query->post = $post; $wp_query->posts = array($post); $wp_query->queried_object = $post; $wp_query->is_single = true; $wp_query->is_singular = true; setup_postdata($post); include get_template_directory() . '/single-amp.php'; exit; } else { wp_die('POST ID NOT FOUND: ' . $amp_url); } } } add_action('template_redirect','ttnews_amp_load',1);