This tutorial will teach you how to create a 404 page for your WordPress blog. If your blog already has this page, you can also learn how to modify the 404 page to make it more user-friendly and personalized. Due to the special nature of the 404 error page, many times people ignore it and do not think about designing it. In fact, the 404 error page may mean that the user leaves or continues to browse your web page. If your 404 page is too monotonous and boring, visitors may not be willing to continue browsing; but if your 404 error page is personalized and friendly, It is likely to attract visitors to other pages of your website.
What is a 404 error page
Most of the time, you build a website and check it multiple times to make sure every link is valid. However, over time you may forget that a link leads to a page that has been deleted or renamed, or may have had its name changed. Or if visitors search for your webpage through a search engine but cannot link to the page, they will also jump to a 404 error page. Generally, WordPress themes include 404.php, and you don’t need to design one separately, but if it doesn’t or you want to have a personalized and creative 404 error page, you can design it separately.
Error 404, translated into Chinese as 404 error page, refers to the page returned when the user opens a link that no longer exists through a search engine or directly. The 404 error page has a special meaning: it feeds back information to the viewer that the requested page does not exist or the link is wrong, and at the same time guides the user to browse other pages of the website instead of leaving directly.
Basic 404.php
Generally speaking, WordPress themes contain 404.php, with some exceptions. WordPress is set up by default to automatically look for the 404.php file when an error occurs on the page, but if this file does not exist, the browser will display an annoying error message. It may even have a negative impact on your blog’s SEO. If your blog theme does not have this file. You can create a new blank file yourself and name it 404.php. Here is the most basic 404.php code: 404.php File
Error 404 - Page Not Found.
The basic code of 404.php includes H2 tags - "Error 404 – Page Not Found", and instructions for reading header, sidebar, and footer. Of course, you can adjust these codes accordingly to suit the template and style of your blog.
We'll break down the tutorial on modifying 404.php in a few steps. Please note that I always use the get_header, get_sidebar and get_footer commands to call the wordpress theme file. You should modify the 404.php file slightly as needed to suit your theme.
Start modifying the 404 error page
First, we will add search code on the 404 error page so that the 404 error page is not too boring and lacks action options. If a visitor browses your 404 page, he can search for your other pages through the search box. This is one way to help you retain visitors.
Add search code for 404.php
Error 404 - Page Not Found.
Search:
Creative 404 error page
Create a creative 404 error page that will briefly distract visitors from the error message before redirecting them to your homepage. 404 error pages can be made as friendly as possible for SEO purposes. Next we will start editing the header.php file in the template. In your header.php at the top of the meta tags, you can add the following code:
Then add the red part of the code to 404.php:
404.php File
Error 404 - File Not Found.
Please return to our home page, or you can wait to be redirected in 15 seconds.
The above example is used to guide visitors from the 404 error page to the homepage of the website. This will also help the website retain users instead of confusing them and eventually leaving. This example may not always be the best solution, but it can be very effective for visitors looking for content on your site.
Make sure the 404 error page works
You can test whether the 404 error page works by entering a page that your page does not exist. (The red part is your homepage address) For example: http://www.yourwebsitedomain.com/test404page.php
This will open your 404 error page, otherwise the test failed.
if test fails
If it happens that your server doesn't automatically open 404.php, you can get support by modifying .htaccess. Find the .htaccess file in the WordPress installation address and add the following code:
ErrorDocument 404 /index.php?error=404
If your WordPress is not installed in the root directory of ftp, but is installed in an ftp subfolder, you must modify the .htaccess file to: (YOURSUBFOLDERNAME, referring to the name of the subfolder)
ErrorDocument 404 /YOURSUBFOLDERNAME/index.php?error=404
This will call your 404.php file. Below is a complete code demonstration that teaches you how to use 404.php to help users find what they are looking for. Give them as much information as possible to entice them to continue browsing other pages.
404 Error
We cannot seem to find what you were looking for.
Maybe we can still help you.
You can search our site using the form provided below.
You can visit "
Or you can view some of our recent posts.
Search:
TEMPLATEPATH . "/searchform.php"); ?>
Recent Posts
endwhile; endif; ?>
You can modify and adjust the code according to your personal preferences and page style. In the above example, we simply tell the viewer that it is a bad link and provide them with options, such as a search box. You can also add a list of latest articles to entice them to continue browsing the site. These options are designed to guide visitors to browse other pages, rather than letting visitors turn around and leave after seeing a 404 error page.
Make 404 error pages more user-friendly
To make the 404 error page more user-friendly, you can use the method described above and add a creative image. You can also use html code in the 404.php file to make the entire page an error page.