I have a URL like http://example.com/arbitrary/path that I would like to map to a specific template file. At the moment I am achieving this by enabling permalinks and creating the pages “arbitrary” and “path” (page “arbitrary” is set to parent of “path”) then choosing a custom template. The downside to this is that the client could delete these pages thus breaking the site.
Anyone know of a better way? Like something I could add to functions.php.
1 Answer
Please place below code in your theme’s functions.php file & let me know how it goes 🙂
add_action('wp', function(){
list($uri, $qs) = explode('?', $_SERVER['REQUEST_URI']);
if ( $uri == "/arbitrary/path" ) /* Change this to path that you want to match*/
{
locate_template( "template-full-width.php" , true, false ); /* Don't forget to replace template name with actual template which you want to load */
die(); /* So that WordPress does not load its template as per template hierarchy. */
}
});