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.

  • Yeah, and if there is a contact page and the client delete it, the site will break too. I think that the reason you are exposing is worthless. Can you deeply explain the context?
    – cybmeta
    Jan 3, 2016 at 14:01

1 Answer 1


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. */
  • Thanks mate works perfect! You even took into account I may be using a query string. Jan 3, 2016 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.