Web Design

How to Build a Helpful Custom 404 Page on WordPress

A WordPress 404 page with a search box and links to key pages

This guide is for bloggers, small business owners and agency teams who run a WordPress site and want visitors who land on a dead URL to find their way instead of leaving. It covers what a good 404 page contains, how to edit it in a block theme or a classic theme, and the search-engine points that are easy to get wrong.

Contents
  1. What a 404 page is and why it matters
  2. What a good 404 page contains
  3. Edit the 404 page in a block theme
  4. Edit the 404 page in a classic theme
    1. Use a child theme
  5. SEO points: get the status code right
    1. Return a real 404 status
    2. Avoid soft 404s
    3. Do not redirect every 404 to the home page
  6. How to check the status code
    1. Browser developer tools
    2. Search Console URL Inspection
  7. Key takeaways
  8. FAQ
    1. Does a custom 404 page hurt SEO?
    2. Should I use 404 or 410?
    3. Will Google keep crawling my 404 pages forever?
  9. Sources

What a 404 page is and why it matters

A 404 page appears when a visitor requests a URL that does not exist on your site. WordPress describes its 404 template as the one used “when WordPress cannot find a post, page, or other content that matches the visitor’s request” (WordPress Theme Handbook). Typical causes are a mistyped address, an old link from another site, or a page you deleted or renamed.

You cannot prevent every dead URL, but you can decide what the visitor sees. A bare “Not found” message sends people back to the search results. A useful page gives them a next step. If you are still hunting for the broken links that cause these errors, our guide to finding and fixing broken links on a WordPress site covers that side of the problem.

Advertisement

What a good 404 page contains

Keep it short and practical. The aim is to help someone recover, not to show off. A solid page usually includes the following:

Enjoying this? Get our best tips by email

Practical SEO, link building and content strategies, straight to your inbox.

No spam. Unsubscribe any time.

  • A plain message. Say clearly that the page could not be found. Avoid jokes that hide the meaning, and avoid blaming the visitor.
  • A search box. Someone looking for a specific topic can type it straight away.
  • Links to key pages. Add your home page, your main categories or services, your contact page and perhaps a short list of recent or popular posts.
  • Your normal header and footer. The site navigation should still work, so the visitor feels they are still on your site.
  • A way to report the problem. Optional, but a contact link lets people tell you about a broken link they followed.

Edit the 404 page in a block theme

The Site Editor is only available when a block theme is active, according to the WordPress.org Site Editor documentation. If you use one, follow these steps:

  1. In the dashboard, go to Appearance → Editor.
  2. Choose Templates. The documentation describes this area as the place to review the default layouts, “as well as custom pages (search results, 404, etc)”.
  3. Open the 404 template. Depending on your theme and WordPress version it may be labelled Page: 404 or simply 404; the documentation does not spell out the exact label, so look for either.
  4. Use the block inserter to add a Search block, a short Paragraph or Heading with your message, and a Navigation or List block with links to key pages.
  5. Click Save. The editor lists every template or template part you changed, and you can save all of them or only some.

The Theme Handbook says block themes use HTML files in place of PHP files, and the 404 template file is 404.html in a block theme. If you want a recent-posts list, the Query Loop block is one of the theme blocks the Site Editor documentation names for laying out posts.

Edit the 404 page in a classic theme

Classic themes use PHP template files. According to the Template Hierarchy page of the Theme Handbook, WordPress looks for 404.php first and, if it is missing, falls back to index.php, which is the final fallback for every request. So creating a 404.php file in your theme is how you control the page.

Use a child theme

If you edit a theme you did not write, your changes can be overwritten when the theme updates. Put the file in a child theme instead. A minimal 404.php usually calls the header, shows your content and calls the footer:

<?php get_header(); ?>

<main id="primary">
  <h1>Page not found</h1>
  <p>We could not find that page. Try a search or one of the links below.</p>
  <?php get_search_form(); ?>
  <ul>
    <li><a href="<?php echo esc_url( home_url( '/' ) ); ?>">Home</a></li>
  </ul>
</main>

<?php get_footer(); ?>

The Theme Handbook mentions get_search_form() as the way to include a search form in a classic theme template. Adjust the markup so it matches your theme’s wrapper elements; the snippet above is an illustration, not a drop-in for every theme.

Advertisement

SEO points: get the status code right

A friendly design is only half the job. The page must also tell browsers and crawlers that the content does not exist.

Return a real 404 status

Google’s Search Central documentation on HTTP status codes explains that Google ignores content returned by URLs that respond with a 4xx code, and that for an already-indexed URL a 404 leads to removal from the index. Newly encountered 404 pages are not processed, and crawling of them gradually slows. That is the behaviour you want for pages that are really gone.

Avoid soft 404s

Google’s crawling-errors guidance defines a soft 404 as a URL that shows a “page not found” message or an empty page while returning a 200 (success) status code. It lists a few causes, including a missing server-side include file, a broken database connection, an empty internal search results page and a missing JavaScript file. For a page that is genuinely gone, the guidance says to return a 404 or 410 code, and adds that a custom 404 page is fine for users as long as the server still returns the 404 code.

In normal use, WordPress sends the 404 status when it renders the 404 template. Problems tend to appear when a plugin, a caching layer, a page builder or a “coming soon” tool serves a normal page with a not-found message on top. If you create a regular page called “Not found” and redirect missing URLs to it, you have built a soft 404.

Do not redirect every 404 to the home page

Blanket redirects can look tidy, but they do not fit Google’s guidance, which is narrower: use a 301 permanent redirect when a page has moved or has a clear replacement, and return a 404 or 410 when there is no replacement with similar content. Search Central also says 301 and 308 are a strong signal that the redirect target should be processed. Sending unrelated dead URLs to the home page tells Google something that is not true, and it confuses visitors who expected a specific page. Google’s page does not address home-page redirects directly, so treat this as a conclusion drawn from the guidance above rather than a quoted rule.

When you have renamed or merged a page, redirect the old address to the closest matching new one. Our walkthrough on setting up 301 redirects on WordPress safely shows how.

Advertisement
SituationRecommended response
Page deleted, no similar content404 (or 410) with a helpful custom page
Page moved or replaced by a close match301 redirect to the new URL
Page still exists but shows an error to GoogleInvestigate blocked resources, server errors or slow loading

How to check the status code

Browser developer tools

  1. Open a made-up URL on your site, such as /this-page-does-not-exist.
  2. Open your browser’s developer tools (usually F12) and select the Network tab.
  3. Reload the page and click the first request, which is the page itself.
  4. Read the status in the headers or the Status column. It should say 404. If it says 200, you have a soft 404.

The exact layout of developer tools differs between browsers, so only the general steps are described here.

Search Console URL Inspection

Google’s guidance says the URL Inspection tool can verify the HTTP code returned and show the rendered content; a blank or error-filled render suggests a soft 404. Soft 404 errors are also listed in the Page Indexing report. For a broader walk-through of reading these reports, see our guide on fixing crawl errors in Google Search Console.

Key takeaways

  • A good 404 page has a plain message, a search box and links to your most useful pages.
  • In a block theme, edit the 404 template under Appearance → Editor → Templates; in a classic theme, create 404.php in a child theme.
  • The page must return a real 404 status. A “not found” message on a 200 page is a soft 404.
  • Use 301 redirects for moved pages and 404 or 410 for pages with no replacement, not a blanket redirect to the home page.
  • Check the status code with browser developer tools and Search Console URL Inspection.

FAQ

Does a custom 404 page hurt SEO?

Not by itself. Google’s guidance says a custom 404 page is fine for users as long as the server still returns the 404 code. The risk comes from serving it with a 200 status.

Should I use 404 or 410?

Google’s soft 404 guidance accepts either for content that is no longer available and has no replacement. The guidance does not describe any difference in how Google treats the two, so a 404 is a reasonable default in WordPress.

Will Google keep crawling my 404 pages forever?

Google’s documentation says newly encountered 404 pages are not processed and crawling of them gradually slows. It does not give a timeframe, so how long that takes is unconfirmed.

Sources

Advertisement