Map arbitrary URL to $mainTemplate using theme wrapper

Let’s say I have an infinite number of arbitrary URLs…


Similar to how Sage loads page.php for pages, can I make Sage load a file named browse.php for anything matching this /browse/ pattern? How would I accomplish this? Preferably, I would like to keep base.php as my base template.


I was able to figure out a way to make the theme wrapper use my custom template, however, while my template content loads in just fine, it’s treating the page as a 404 page. So the page title is “Page Not Found” and functions such as is_404() are returning true. Is there any way to map a page and have WordPress think it’s a valid page?

Here’s the code I came up with…

add_filter(‘template_include’, function($template) {
global $wp_query;
if ($wp_query->query[‘category_name’] === ‘browse’) {
$template = locate_template(array(‘browse.php’));
return $template;
}, 99);

This works because my permalink structure is set to /%category%/%postname%/