Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Setup & site building · Guide

How to Create a Custom 404 Page in WordPress

How to Create a Custom 404 Page in WordPress

Short answer

On a block theme, open Appearance, then Editor, then Templates, pick 404, and build the page with blocks. On a classic theme, add a 404 template file to a child theme with a header call, a message and a search form, and a footer call. Either way, the page must still return a 404 status code, not a 200 code.

Key takeaways

  • A 404 page shows when a visitor opens a URL that does not exist.
  • Block themes use templates/404.html, and classic themes use 404.php.
  • In the Site Editor, open Templates, pick 404, and build with blocks.
  • A custom 404 page must still return a 404 status code, not 200.
  • A page that says 'not found' while returning 200 is a soft 404.

What is a custom 404 page?

A custom 404 page is a page you design for visitors who open a URL that does not exist, instead of showing the theme's plain error text.

Learn WordPress's 404 tutorial defines the 404 page as the content a visitor sees when they try to reach a page that does not exist on your site. Most people who land on a default 404 page leave the site at once, so a useful page keeps them around.

The page does not fix the broken link. It gives the lost visitor a way back to working pages, with a search box, a home button, and links to popular content.

Every WordPress site already has a 404 page from its theme, so this guide is about replacing the default text with something more useful. You do not need a plugin for either route below.

A custom 404 page is a template, not a page with its own URL. WordPress shows it whenever a requested URL matches no post, page, product, or archive in the database.

How do you know which kind of theme you have?

Open Appearance in the admin menu: if you see Editor, you run a block theme; if you see Customize, you run a classic theme.

WordPress.com's site icon guide gives the same test: Editor under Appearance means a block theme, and Customize means a classic theme. That one check decides which route below to follow.

The file you edit follows from that answer. Block themes use templates/404.html, and classic themes use 404.php. Editing the file for the wrong theme type changes nothing visitors see.

The Theme Handbook's template hierarchy page lists 404.php as the template for missing pages, with index.php as the fallback. WordPress walks the hierarchy until it finds a matching file, and index.php catches anything left over.

Theme type404 templateWhere you edit it
Block themetemplates/404.htmlAppearance, then Editor, then Templates, then 404
Classic theme404.phpChild theme folder

The guide to block themes vs classic themes explains the two theme types in full. If you are unsure which theme is active, check Appearance, then Themes, where the active theme is marked.

How do you build a 404 page in the Site Editor?

Go to Appearance, then Editor, open Templates, pick 404, and build the page with blocks.

Learn WordPress's 404 tutorial walks through the route: open the Site Editor, open Templates, select the 404 template, and edit it with blocks such as Cover, Columns, Heading, Buttons and Search. The canvas loads the theme's existing 404 template, so you start from what the theme already shows.

Add a short message, a search block, and a button back to the homepage. Keep the header and footer template parts in place, so the page still looks like the rest of the site.

The same tutorial shows a second route: copy a 404 pattern from wordpress.org/patterns and paste it into the template. Pick a pattern you like, copy it, and paste it into the template canvas, then adjust the text to fit your site.

If the result looks wrong, open the three-dot menu next to the 404 template and pick Clear customizations to revert it. The tutorial notes that the template then returns to its original state.

Click Save when the design is ready, then open a dead URL to see the result. The guide to using the WordPress Site Editor covers templates and template parts in more detail.

The Site Editor route needs no code and no plugin. The 404 template is a normal template you can edit with blocks.

How do you build a 404 page with 404.php?

Create a file named 404.php in the child theme folder, with the header and footer calls and your message in between.

The Theme Handbook's 404 pages page states that the first step is to create a file named 404.php and add it to your WordPress theme folder. Put the file in a child theme, not the parent theme, so a parent update does not delete it.

Add this code to the new file:

<?php
/**
 * The template for displaying 404 pages (Not Found)
 */
get_header();
?>
<p>That page is gone or was never here. Try a search, or go back to the homepage.</p>
<?php get_search_form(); ?>
<?php get_footer(); ?>

The handbook's example starts with get_header(), adds a message and get_search_form() in the body, and ends with get_sidebar() and get_footer(). That example comes from the Twenty Thirteen theme that ships with WordPress.

Copy the parent theme's 404.php first when it has a layout you like, then edit the copy. Starting from the parent file keeps the theme's own markup and classes, so the page matches the rest of the site.

The guide to what a child theme is explains how to set one up. If you have no child theme yet, create one before you add the 404.php file.

Upload the file with SFTP or your host's file manager, then test it with a made-up URL. The change shows at once, with no activation step in the admin area.

What should a good 404 page include?

A good 404 page says plainly that the page is missing, then offers a search box, a home button, and links to popular pages.

Keep the message short: one line that says the page is gone, and one line that points the visitor onward. A visitor who lands here is already lost, so the page should guide, not explain.

Add a search block or search form so the visitor can find the page by name. Many visitors know what they wanted and only mistyped the address, so search is the fastest way back.

Link a few popular pages or posts, and keep the header and footer so the page still looks like your site. A page that looks like an error from another site pushes visitors away.

Skip jokes that hide the message, and skip long text. A lost visitor wants a way forward, not a story, and a funny line only works when the way back is clear.

A contact link helps when the visitor thinks the page should exist. One line such as “Tell us about the broken link” with a link to the contact page turns a dead end into a report you can act on.

How do you test the 404 page?

Type a URL on your site that does not exist, such as /fred.php, and confirm your custom page loads.

The Theme Handbook suggests exactly that test: type a made-up address, which is sure to give a 404 error unless a file by that name exists. Open the address while logged out, so you see the page as a visitor sees it.

Check the page on a phone as well as a desktop, since the search box and buttons must work on a small screen. A button that sits off screen on a phone is no help to a lost mobile visitor.

Confirm the page still returns a 404 status code, not a 200 code. Open the browser developer tools, check the network tab, and confirm the response code for the dead URL is 404.

If the old default page shows instead, you edited the wrong theme or the wrong file. Check which theme is active under Appearance, then Themes, and confirm the file sits in that theme's folder.

Test two or three dead URLs, not just one. A page that works for a mistyped post address should also work for a mistyped page address, since both use the same template.

Will a custom 404 page hurt your search rankings?

No: a custom 404 page does not hurt rankings, as long as the page still returns a 404 status code.

Google's Search Central troubleshooting guide states that a soft 404 is a page that says the page does not exist while returning a 200 success code, and that such pages are excluded from Search. The status code is what matters, not the design.

The same guide states that custom 404 pages are created solely for users, and that the server must return a 404 status code to keep the pages out of the index. A custom design never changes the code WordPress sends, so the page stays out of the index either way.

Google's own blog on 404 errors states that 404 errors are a normal part of the web and do not affect how a site's other URLs perform in search results. A few dead URLs are expected on any site that changes over time.

Do not redirect every dead URL to the homepage. A redirect that returns 200 for a missing page creates the soft 404 problem above, and Google flags it in the Page Indexing report.

Fix real broken links instead of hiding them. The guide to fixing 404 errors for SEO in WordPress covers that job, including which dead URLs deserve a redirect to a live page.

What mistakes should you avoid?

Do not build a 404 page that returns a 200 code, do not redirect dead URLs to the homepage, and do not edit 404.php inside the parent theme.

Other mistakes to avoid:

  • Editing 404.php in the parent theme, where the next theme update wipes the change.
  • Redirecting all dead URLs to the homepage, which turns them into soft 404s.
  • Filling the page with links to every post, which buries the way back.
  • Leaving the default message with no search box and no home button.
  • Writing a long apology that pushes the search box below the fold on a phone screen.

If real posts return 404 errors, the fault is elsewhere. The guide to what causes 404 errors on posts covers the fixes.

The guide to fixing 404 errors on posts walks through the same fixes, which usually sit in the permalink settings.

Check the 404 page after every theme change. A new theme brings its own default 404 template, so a redesign can silently replace your custom page.

Frequently asked questions

Do I need a plugin for a custom 404 page?

No. A block theme lets you edit the 404 template in the Site Editor, and a classic theme needs only a 404.php file in a child theme. Plugins can add design options, but neither route in this guide needs one.

How do I test my custom 404 page?

Type a URL on your site that does not exist, such as /fred.php, and confirm your custom page loads. Check it on a phone as well as a desktop, and confirm the page still returns a 404 status code.

Will a custom 404 page hurt my SEO?

No, as long as the page still returns a 404 status code. Google states that 404 errors are a normal part of the web and do not affect how a site's other URLs perform. A page that returns 200 for a missing URL is a soft 404, which Google excludes from Search.

Where do I edit the 404 page on a block theme?

Go to Appearance, then Editor, open Templates, and pick 404. Build the page with blocks, add a search block and a home button, then click Save. Pick Clear customizations from the template menu to revert it.

Why does my 404 page show the old default text?

You may have edited the wrong theme or the wrong file. Check which theme is active under Appearance, then Themes, and confirm the 404.php file or the Site Editor change sits in that theme. A new theme also brings its own default 404 template.

Sources

  1. 404 Pages - Theme Handbook Developer.WordPress.org
  2. Template Hierarchy - Theme Handbook Developer.WordPress.org
  3. Personalizing your 404 Template Learn WordPress
  4. Troubleshoot Google Search Crawling Errors Google Search Central
  5. Do 404 errors hurt my site? Google Search Central Blog

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.