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 friendly and personal. Due to the special nature of the 404 error page, people often ignore it and have never thought 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, tourists may not be willing to browse it; but if your 404 error page is personalized and friendly, It is likely to attract tourists to browse other pages of your page.
What is 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 points to a page that has been deleted or has changed its name, or may have changed its name. Or if a tourist searches your web page through a search engine but cannot link to the page, it will also jump to the 404 error report page. Generally speaking, wordpress themes contain 404.php, you don't need to design one separately, but if you don't or you want to have a personalized, creative 404 error page, you can design it separately.
Error 404, translated into 404 error page in Chinese, refers to the page returned when a user uses a search engine or directly opens a link that no longer exists. The 404 error page has a special meaning: feedback to the browser that the page it requests does not exist or links are incorrect, and guides the user to browse other pages of the website instead of leaving directly.
Basic 404.php
Generally speaking, wordpress themes contain 404.php, except for a few. WordPress is set by default to automatically look for a 404.php file when a page error occurs, but if this file does not exist, the browser will display an annoying error message. It may even have a negative impact on the SEO of your blog. If your blog topic does not have this file. You can create a new blank file yourself, named 404.php. Here is the most basic 404.php code: 404.php File
Error 404 - Page Not Found.
404.php's basic code includes H2 tags ——“Error 404 – Page Not Found;, reading the header, sidebar, and footer instructions. Of course, you can make corresponding adjustments to these codes as needed to adapt to the templates and styles of your blog.
We will use several steps to decompose and modify the 404.php tutorial. Please note that I always use the get_header, get_sidebar and get_footer commands to call the wordpress theme file. You should slightly modify the 404.php file to suit your theme as needed.
Start modifying the 404 error page
First, we will add the search code to the 404 error page so that the 404 error page will not be too monotonous and lack operation options. If a tourist browses your 404 page, he can search for other pages through the search box. This is a way to help you retain tourists.
Add search code for 404.php
Error 404 - Page Not Found.
Search:
Creative 404 Error Page
Create a creative 404 error page with the goal of having the viewer stay on the wrong message for a short time and redirect them to your homepage. The 404 error page can be made as friendly as possible to achieve SEO. Next we will start editing the header.php file in the template. In your header.php in meta tags at the top, you can add the following code:
Then add the red part of the code in 404.php:
404.php File
Error 404 - File Not Found.
Please to 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 home page of the website. This will also help the website retain users, rather than letting them feel confused and eventually leave. This example may not always be the best solution, but it is very effective for tourists to find the content on your website.
Make sure the 404 error page works
You can test whether the 404 error page is valid by typing a page that does not exist on your web page. (The red part is your homepage address) For example: http://www.yourwebsitedomain.com/test404page.php
This will open your 404 error page, if not, the test failed.
If the test fails
If it happens that your server does not automatically open 404.php, you can get support by modifying .htaccess. Find the .htaccess file at 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 the 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 to use 404.php to help users find what they originally wanted. Feed back some information to them as much as possible to attract 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 example above, we just tell the viewer that it is a wrong link and provide them with options for action, such as the search box. You can also add a list of latest articles to attract them to continue browsing the website. These options are all designed to guide tourists to browse other pages, rather than letting tourists see the 404 error page and turn around and leave.
Make the 404 error page more friendly
To make the 404 error page more friendly, you use the methods described above and add a creative picture. You can also use html code in the 404.php file to get the entire page is an error page.