How to make page 404 WordPress
Create a unique 404 page for your WordPress site with this step-by-step guide and example.
Creating a Custom 404 Page in WordPress
A 404 error page occurs when a user tries to visit a page or URL that does not exist. By creating a custom 404 page in WordPress, you can make sure your visitors stay on your website and help them find the content they are looking for. Here is a step-by-step guide on how to make a 404 page in WordPress.
Step 1: Create a 404 Template File
The first step is to create a 404 template file. This file will contain the HTML and PHP code that will be used to display the 404 page. To create the file, you will need to open a text editor, such as Notepad or TextMate, and save the file as 404.php in your WordPress theme folder. Once the file is saved, you can add the following code to it:
<?php
/*
Template Name: 404 Page
*/
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<article id="post-0" class="post error404 not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Oops! That page can’t be found.', 'your-theme-slug' ); ?></h1>
</header>
<div class="entry-content">
<p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'your-theme-slug' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
This code displays a basic 404 page with a message and a search box. You can customize the message by replacing the text in the <h1>
and <p>
tags.
Step 2: Set a Custom 404 Page
Once you have created the 404 template file, you need to set it as your custom 404 page. To do this, you need to go to Settings > Reading in your WordPress dashboard. On the Reading page, you will see an option called Front page displays. Under this option, you will see a drop-down menu labeled 404 pages. From the drop-down menu, select the Custom option. This will set your custom 404 template as the 404 page for your website.
Step 3: Test Your Custom 404 Page
Once your custom 404 page has been set, you can test it by going to a non-existent page on your website. For example, if your website's URL is www.example.com, then you can go to www.example.com/non-existent-page to test your custom 404 page. If everything has been set up correctly, you should see your custom 404 page on this page.
Conclusion
Creating a custom 404 page in WordPress is a great way to make sure your visitors stay on your website and help them find the content they are looking for. With a few simple steps, you can have a custom 404 page up and running in no time.