add_rewrite_tag($qrr_rewrite_tag, '([^/]+)', "{$qrr_query_var}="); // Create the structure off of root. $structure = $wp_rewrite->root . $qrr_link_base . "/{$qrr_rewrite_tag}"; // Make those rules $rules = $wp_rewrite->generate_rewrite_rule($structure); // Append the rules to the rules array in the rewrite object. $wp_rewrite->rules += $rules; } // This adds qrr as a recognized query var. It will be processed out // of GET, PATH_INFO, or REQUEST_URI depending on how the permalink was // requested. WP handles the particulars, you don't have to care. The value // of qrr will be made available via the WP_Query object and // get_query_var(). function qrr_add_query_var($vars) { global $qrr_query_var; // Append qrr. $vars[] = $qrr_query_var; // Don't forget to return the array. return $vars; } // If qrr is set, redirect to qrr.php. function qrr_template_redirect() { global $qrr_query_var; // Get the qrr from WP_Query. $qrr = get_query_var($qrr_query_var); // If it's empty, return. if (empty($qrr)) return; // Otherwise, load our template. // You must use load_template rather than require or include. // load_template() sets up the necessary environment. load_template(ABSPATH . "wp-content/{$qrr_query_var}.php"); // Make sure you exit after loading a template. exit; } // Hook 'em in. add_filter('query_vars', 'qrr_add_query_var'); add_action('generate_rewrite_rules', 'qrr_generate_rewrite'); add_action('template_redirect', 'qrr_template_redirect'); ?>