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’. add_action(‘init’, function() { $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), “https://wordpress.stackexchange.com/”); if ( $url_path === ‘retail’ ) { // load the file if exists $load = locate_template(‘template-retail.php’, true); if ($load) { exit(); // just exit … Read more

How to create custom URL routes?

Add this to your theme’s functions.php, or put it in a plugin. add_action( ‘init’, ‘wpse26388_rewrites_init’ ); function wpse26388_rewrites_init(){ add_rewrite_rule( ‘properties/([0-9]+)/?$’, ‘index.php?pagename=properties&property_id=$matches[1]’, ‘top’ ); } add_filter( ‘query_vars’, ‘wpse26388_query_vars’ ); function wpse26388_query_vars( $query_vars ){ $query_vars[] = ‘property_id’; return $query_vars; } This adds a rewrite rule which directs requests to /properties/ with any combination of numbers following to … Read more