How do I create a custom 404 page in WordPress?

Applies to: WordPress.org (self-hosted)
Last updated: May 2025


Problem

When a user lands on a non-existent URL, they see a generic “404 Page Not Found” message. You want to customize this page to improve user experience and guide visitors back to useful content.


Solution

You can customize your 404 page by editing your theme’s 404.php file, using a page builder, or installing a plugin—depending on your level of experience and your theme setup.


Option 1: Using a Theme That Supports Custom 404 Pages

Some themes (especially premium or page-builder-based themes like Astra + Elementor) allow you to assign any page as the 404 template.

  1. Create a new page called 404 Error (or similar)
  2. Add custom content:
    • Apology message
    • Search bar
    • Popular posts or categories
    • Button to return to homepage
  3. Use your theme’s custom layout settings or header/footer builder to assign it as the 404 template (check theme docs)

Option 2: Edit the 404.php Template Manually

If you’re comfortable with code:

  1. Go to your theme directory: /wp-content/themes/your-theme/
  2. Locate the file named 404.php
    • If it doesn’t exist, you can create it
  3. Customize the HTML and PHP inside to include:
    • Custom message
    • Link back to homepage
    • Optional search form: <?php get_search_form(); ?>
  4. Save the file and refresh a broken link to test it

Important: Use a child theme if editing theme files directly to avoid losing changes during theme updates.


Option 3: Use a Plugin (No Coding Required)

Install a plugin like:

  • 404page – your smart custom 404 error page
  • SeedProd (lite or pro) — works with custom 404 templates

Steps:

  1. Install and activate the plugin
  2. Create a new WordPress page with your desired 404 content
  3. Go to Appearance > 404 Error Page (or plugin settings)
  4. Select the custom page as your 404 page
  5. Save changes

What to Include on a Custom 404 Page

  • A friendly error message (e.g., “Oops! Page not found.”)
  • A search bar
  • Links to key pages (Home, Blog, Contact)
  • A list of popular or recent posts
  • A button to return to the homepage

Notes

  • Always test your 404 page by entering a fake URL (e.g., yoursite.com/does-not-exist)
  • A custom 404 page helps reduce bounce rates and improves user experience
  • Use Google Search Console to track 404 errors and fix broken links when possible

You may also like...