title: WordPress + Timber w/ custom theme + routing - 404 page not rendering
body: <p>I am creating a custom WordPress theme using <a href="https://timber.github.io/docs/" rel="nofollow noreferrer">Timber</a> and <a href="https://twig.symfony.com/doc/2.x/templates.html" rel="nofollow noreferrer">Twig</a> and I am having a hard time getting my custom 404 page to render.</p>
  
  <p>Originally, each page on my website had a custom route defined in <code>functions.php</code> and my 404 logic was in <code>index.php</code>. This is probably not the best way to accomplish this, but it is the only way I could get it working -- I couldn't find much about creating 404 pages with a custom theme in the Timber documentation.</p>
  
  <p><code>index.php</code>:</p>
  
  <pre><code>&lt;?php
  $context = Timber::get_context();
  $post = new TimberPost();
  $context['page'] = $post;
  global $wp;
  $url = home_url($wp-&gt;request);
  $context['url'] = preg_replace('#^https?://#', '', rtrim($url, '/'));
  
  Timber::render('views/pages/404.twig', $context);
  </code></pre>
  
  <p>This worked great until I needed to add a wildcard route so that the client could add new pages on their own without asking us to add a new route. I added this wildcard route for pages to <code>functions.php</code>:</p>
  
  <pre><code>Routes::map('/:page', function($params) {
  Routes::load('routes/page.php', $params, null, 200);
  });
  </code></pre>
  
  <p>The wildcard route is working as intended, but now my 404 logic from above is no longer working. When I visit a URL that is not a page that has been created in the WordPress admin, it sends me to a page with a random post's content in it. I'm a little lost at how to get this working properly, it is likely that my initial 404 logic is not the correct way to handle it. Any advice would be great.</p>
  
  <p>I have tried to add a <code>404.php</code> to the theme folder with this code:</p>
  
  <pre><code>&lt;?php
  $context = Timber::get_context();
  
  Timber::render( array(
  'views/pages/404.twig'
  ), $context );
  </code></pre>
  
  <p>This unfortunately did not work -- at a random URL my website is rendering a random post's content and not the <code>404.twig</code> file.</p>