2.14.1.18. Configure 404 page in WordPress

In WordPress, you can configure a custom 404 page by modifying the theme template.

  1. Go to the "Appearance → Theme editor" section:
  2. On the right side of the page, select the theme you want to edit and find "404 error template":(It is worth noting that child themes may not have these templates, as they are inherited from the parent theme.)
  3. Once you've selected a template file, its contents will open, and you'll need to make changes to create the page you want. Here are a few important elements:
    • To specify the search field, use the following code snippet:
      <?php get_search_form(); ?>
    • To indicate that the error message can be translated, insert the text into the following function:
      <?php _e('text'); ?>
  4. Click "Update file".

The default template for the Twenty Nineteen theme looks like this:

<?php
get_header();
?>
<section id="primary" class="content-area">
  <main id="main" class="site-main">
    <div class="error-404 not-found">
      <header class="page-header">
        <h1 class="page-title"><?php _e( 'Oops! That page can’t be found.', 'twentynineteen'); ?></h1>
      </header><!-- .page-header -->
      <div class="page-content">
        <p>
          <?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentynineteen' ); ?>
        </p>
        <?php get_search_form(); ?>
      </div><!-- .page-content -->
    </div><!-- .error-404 -->
  </main><!-- #main -->
</section><!-- #primary -->
<?php
get_footer();
Content