As bloggers, we try our best to ensure that every link we create goes to a specific page on our site. However, in the event that we delete out-of-date posts or pages without removing the links to them, there is a chance that a link clicked will lead to Error 404 page. Instead of displaying your visitors “Sorry, page not found”, you should put more helpful message suggesting them what to do next such as go to homepage, contact administrator, or perform searches.
In today’s post, we will teach you how to customize your Error 404 page so that it’s more helpful to your visitors and consistent with your theme style.
How to Edit an Error 404 Page
Most of the WordPress themes have their own Error 404 template file. It is used to inform your visitors when a “Page not found” error occurs. However if you don’t like the default error message, you can actually edit it with some helpful suggestions to help you visitors find their way.
Following are the steps to edit your Error 404 template file:-
1. Go to your WordPress admin panel.
2. Click “Appearance” on the left sidebar, and then choose “Editor” from the drop down list.
3. Check to see if your theme has 404 template file.
4. Click on “404 Template” link to open the file.
5. Edit the Error 404 message text to say what you want it to say.
6. Update the file. (If the template file is not writable, change the file permissions.)
404 Template File Sample
Below is the example of 404 template file for your reference:-
<?php get_header(); ?> <div id="content" class="column"> <h2><?php _e('Error '); ?> 404 – <?php _e('Page not found'); ?></h2> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
How to Create an Error 404 Page
If your current WordPress theme doesn’t come with a 404 template file, you can create your own. Simply copy the file from the default WordPress theme: /wp-content/themes/default/404.php into the directory of your current theme.
However there’s no guarantee that copying over the 404 template file will work because every theme is different. You might need to change the template file’s header, sidebar, footer, and other codes to match your theme’s layout.
How to Redirect Error 404 Page to Homepage in WordPress
Some bloggers prefer to redirect Error 404 page to their homepage. Basically there are two ways of doing it.
You can copy the index.php file of your current theme and change the file name to 404.php, so that your visitors can be taken to your homepage whenever they click a link to a non-existent page.
Alternatively you can use a code snippet by following the simple steps below:-
1. Follow the step 1 ~ 4 as mentioned in the “How to Edit an Error 404 Page” tutorial.
2. Replace the existing code completely with the code snippet below.
<?php $URL= get_bloginfo('url'); header("Location: $URL"); ?>
3. Save the changes.
If you want to redirect 404 page to other webpage instead of homepage, all you have to do is replace the “$URL” in the line number 3 with the custom link you want.
How to Help Web Server Find Your Error 404 Page
In the event that your web server encounters a problem and it’s not able to bring your visitors to 404 page, you can modify your .htaccess file to make it work. You’ll need to locate the .htaccess file in the main directory of your WordPress installation and add the following line to it:
ErrorDocument 404 /index.php?error=404
If your WordPress is installed in a subfolder or subdirectory of your site’s root folder named “wordpress”, modify your .htaccess like this:
ErrorDocument 404 /wordpress/index.php?error=404
How to Set up a Custom Error 404 Page through GoDaddy
If you are hosting your website / blog on GoDaddy, go to its 404 Error Options page to set your homepage as 404 page or you can create a custom one. Here’s the steps:-
1. Log in to your Godaddy Account Manager.
2. Click on “Web Hosting”.
3. Next to the hosting account you want to use, click on “Launch”.
4. Click on “Settings” and then choose the “404 Error Options” icon.
5. Select one of the 404 page options (home page, custom page or GoDaddy’s default 404 error page).
6. Click Continue.
7. Verify your 404 error page behavior. If everything looks OK, click Submit.
(Image Source: 501st.com)