Use a template file for a specific url without creating a page
You can just look at url, load the file and exit. That can be done when WordPress loaded its environment, e.g. on ‘init’.
1 2 3 4 5 6 7 8 9 10 | add_action('init', function() { $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/'); if ( $url_path === 'retail' ) { // load the file if exists $load = locate_template('template-retail.php', true); if ($load) { exit(); // just exit if template was found and loaded } } }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.