WP AI Agent
Features Pricing Blog Contact Download Plugin Manage Subscription Get Free Key →

How to Create a 404 Error Page in WordPress: Complete Guide

· · 8 min read

Knowing how to create a 404 error page in WordPress is an essential skill for any site owner who wants to retain visitors, protect SEO, and deliver a polished user experience. By default, WordPress includes a basic 404 template, but a customised page can transform a dead end into a helpful, on-brand interaction that guides users back to your content.

What Is a 404 Error Page and Why Does It Matter?

A 404 error occurs when a visitor tries to reach a URL that does not exist on your server. This happens after URL changes, deleted posts, mistyped links, or broken external backlinks. Without a well-designed 404 page, visitors see a confusing dead end and leave immediately, increasing your bounce rate and signalling poor quality to search engines.

A well-crafted 404 page should:

  • Clearly explain that the requested page was not found
  • Match your site branding and visual style
  • Provide navigation links, a search bar, or popular content suggestions
  • Offer a direct link back to the homepage
  • Optionally log the error so you can fix broken links over time

Investing a small amount of time in your 404 page improves both user experience and long-term SEO health.

Method 1: Editing the Theme 404.php Template

The most direct way to create a custom 404 error page in WordPress is by editing or creating a 404.php template file inside your active theme. This method gives you full design control without relying on a plugin.

Step 1 — Check Whether Your Theme Already Has a 404 Template

  1. Log in to your WordPress dashboard.
  2. Navigate to Appearance > Theme File Editor (or use an FTP client).
  3. Look for a file named 404.php in the list of theme files on the right.
  4. If the file exists, click it to open and edit it. If it does not exist, you will create one in the next step.

Step 2 — Create or Modify 404.php

  1. If no 404.php exists, create a new file in your child theme directory (never edit the parent theme directly).
  2. Open the file and add a structure that includes your theme header and footer, a clear message, and helpful navigation links.
  3. Use the example below as a starting template:
<?php
/**
 * Custom 404 Error Page Template
 * Place this file in your child theme folder as 404.php
 */
get_header(); ?>

<main id="main" class="site-main">
  <section class="error-404 not-found">
    <header class="page-header">
      <h1 class="page-title">Oops! Page Not Found (404)</h1>
    </header>
    <div class="page-content">
      <p>Sorry, the page you are looking for does not exist.</p>
      <p><a href="<?php echo esc_url( home_url( '/' ) ); ?>">Return to Homepage</a></p>
      <?php get_search_form(); ?>
    </div>
  </section>
</main>

<?php get_footer(); ?>
  1. Save the file and visit a non-existent URL on your site (e.g., yoursite.com/this-page-does-not-exist) to preview the result.

Step 3 — Style Your 404 Page

Add CSS rules to your child theme's style.css file to style the .error-404 section. Match your fonts, colours, and layout to the rest of your site for a seamless experience.

Method 2: Using a Block Theme with Full Site Editing (FSE)

If you are running a block-based theme such as Twenty Twenty-Three or Twenty Twenty-Four, you can design your 404 page visually using the Full Site Editor (FSE) without touching any code.

Creating a 404 Template in the Site Editor

  1. Go to Appearance > Editor in your WordPress dashboard.
  2. Click Templates in the left-hand panel.
  3. Look for the 404 template in the list. If it exists, click it to edit. If not, click the + (Add New Template) button and select 404.
  4. Use the block editor to drag and drop blocks — add a Heading block with your error message, a Search block, a Navigation block, and any images or buttons you want.
  5. Click Save when finished.

The FSE approach is ideal for non-developers because it provides a live visual preview and requires no PHP knowledge.

Method 3: Using a WordPress Plugin

Plugins provide the quickest route to a feature-rich 404 page, especially if you want analytics, redirects, and visual customisation without code.

Recommended Plugins for 404 Pages

  • 404page — A lightweight plugin that lets you assign any existing WordPress page as your 404 page.
  • Rank Math SEO — Includes a 404 monitor that logs broken URLs alongside its SEO features.
  • Yoast SEO (Premium) — Offers redirect management to handle 404 errors automatically.
  • Redirection — Logs 404 errors and allows you to create redirects directly from the error log.

Using the 404page Plugin

  1. Go to Plugins > Add New and search for 404page.
  2. Install and activate the plugin.
  3. Create a new WordPress page (Pages > Add New) and design it using the block editor — add a heading, body text, search form block, and a button linking to your homepage.
  4. Publish the page.
  5. Navigate to Appearance > 404 Error Page in your dashboard.
  6. Select the page you just created from the dropdown menu.
  7. Click Save Settings.

Your custom page will now be served automatically whenever a visitor hits a missing URL, regardless of your theme's built-in 404 template.

Method 4: Setting Up 404 Redirects with WP-CLI

For developers managing WordPress from the command line, the Redirection plugin exposes WP-CLI commands that let you monitor and manage 404 errors efficiently.

Installing and Using the Redirection Plugin via WP-CLI

  1. Open your terminal and SSH into your server.
  2. Navigate to your WordPress installation directory.
  3. Run the following commands:
# Install and activate the Redirection plugin
wp plugin install redirection --activate

# List all logged 404 errors captured by the plugin
wp redirection 404s list

# Create a redirect from a broken URL to the homepage
wp redirection create --source="/old-broken-page" --target="/" --regex=0

# Flush the redirect cache after making changes
wp cache flush
  1. Monitor your 404 logs regularly and create redirects for high-traffic broken URLs to preserve link equity and improve user experience.

Enabling 404 Logging in wp-config.php

You can also enable WordPress debug logging to capture 404 events in your server logs. Add the following lines to your wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

This writes errors to wp-content/debug.log, which you can review periodically to identify patterns in broken URLs.

Best Practices for Your WordPress 404 Page

Creating the page is only the first step. Making it effective requires following proven design and content practices.

Content to Include on Every 404 Page

  • Clear error message — Tell the user plainly that the page was not found, without overly technical language.
  • Search bar — Let users search for what they were originally looking for using get_search_form() or a Search block.
  • Navigation links — Link to your homepage, popular categories, or top posts so visitors have somewhere useful to go.
  • Call to action — Include a button or link with a clear label such as "Go Back Home" or "Browse All Articles".
  • Consistent branding — Use the same header, footer, fonts, and colour palette as the rest of your site.

SEO Considerations

A 404 page must return an actual HTTP 404 status code to search engines. WordPress handles this automatically when using 404.php or the 404page plugin, but verify it using a tool like Google Search Console or an HTTP header checker. Never redirect all 404 errors to your homepage with a 200 status code — this is called a soft 404 and is penalised by Google.

Monitoring and Maintenance

Set a monthly reminder to check Google Search Console's Pages > Not Found (404) report. Fix or redirect any URLs that still receive significant traffic. Broken links from other websites pointing to your 404 page waste crawl budget and lose potential referral traffic.

Creating, refining, and maintaining a custom 404 error page in WordPress is straightforward when you follow the methods above. Whether you prefer editing PHP templates, using the visual block editor, or installing a dedicated plugin, you now have the knowledge to deliver a helpful experience to every visitor who hits a dead end on your site. For those who want an even faster path, WP AI Agent is a natural-language AI chat tool that can handle WordPress tasks like creating and customising 404 pages, installing plugins, and editing theme files — all through a simple conversational interface, no manual steps required.

Frequently Asked Questions

Does WordPress automatically create a 404 page?

Yes, WordPress serves a default 404 page using your theme's 404.php template if one exists, or falls back to a generic error message. However, the default page is often plain and unbranded, which is why customising it is strongly recommended.

Will a custom 404 page hurt my SEO?

No — as long as your 404 page returns a proper HTTP 404 status code, it will not hurt your SEO. In fact, a well-designed 404 page that keeps visitors on your site can indirectly improve engagement metrics. The harmful scenario is a "soft 404" where a missing page returns a 200 OK status.

How do I find out which pages on my site are returning 404 errors?

Use Google Search Console under Indexing > Pages and filter by "Not found (404)". You can also use the Redirection plugin's built-in 404 log, or check your server's access and error logs for entries with a 404 status code.

Can I use a page builder like Elementor to design my 404 page?

Yes. You can create a page in Elementor and then assign it as your 404 page using the 404page plugin or through Elementor's own Theme Builder (available in Elementor Pro), which includes a dedicated 404 page template type.

Ready to manage WordPress with AI?

Get 100,000 tokens free every month. No credit card required.

Get Your Free License Key →

More from the blog