While you work hard to ensure that every link on your site leads to a specific web page, there is always the possibility that a link will slam dunk and become a renowned 404 ERROR PAGE NOT FOUND.
There is hope. If a visitor encounters an error, why not be a helpful WordPress site administrator and display a message that is more informative than “NOT FOUND”?
This tutorial will show you how to make your “error” and “page not found” notifications more useful to your visitors by editing them. We’ll also teach you how to make sure your custom messages are shown on your web server. Finally, we’ll go over how to make a custom error page that matches the aesthetic of your theme.
An Ounce of Prevention
Some problems can be avoided by checking and double-checking all of your links on a regular basis. Also, if you’re going to remove a popular but out-of-date post, consider removing the body of the post and replacing it with a link to the new page.
Understanding Web Error Handling
Even the most well-designed websites include flaws. You can delete out-of-date posts as a site administrator, but another website may contain a link to your post’s interior page.
When a user clicks on a link to a page that no longer exists, the web server returns an error message such as 404 Not Found. Unless your webmaster has developed special error messages, the normal message will appear in plain text, which may leave users perplexed.
Most users can hit the back key, but you’ve already lost a visitor who doesn’t want to waste their time looking for the information. At the very least, you’ll want your personalized message to include a link to your home page so that you don’t lose that visitor.
Recognizing the error and assisting them in finding their way is a nice method to manage errors. This entails either building a new Error Page or changing the one included with your WordPress theme.
Editing an Error 404 Page
Every theme that is shipped with WordPress has a 404.php file, but not all Themes have their own custom 404 error template file. If they do, it will be named 404.php. WordPress will automatically use that page if a Page Not Found error occurs.
A 404.php file is included with every WordPress theme, although not all themes have their own custom 404 error template file. If they do, the file’s name will be 404.php. If a Page Not Found issue occurs, WordPress will automatically redirect to that page.
To change the message text in your Theme’s 404 error template file, open it in your favorite text editor and make the changes you wish. Then save your changes and upload it to your WordPress installation’s theme directory.
Take a look at the straightforward structure of the 404.php file that comes with Twenty Thirteen while you’re studying and editing your 404 template file. It consists of tags that display the header, sidebar, and footer, as well as a message area:
<?php
/**
* The template for displaying 404 pages (Not Found)
*
* @package WordPress
* @subpackage Twenty_Thirteen
* @since Twenty Thirteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<header class="page-header">
<h1 class="page-title"><?php _e( 'Not Found', 'twentythirteen' ); ?></h1>
</header>
<div class="page-wrapper">
<div class="page-content">
<h2><?php _e( 'This is somewhat embarrassing, isn’t it?', 'twentythirteen' ); ?></h2>
<p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentythirteen' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .page-content -->
</div><!-- .page-wrapper -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
So, to change the error message your visitor sees, revise the text within the h1 heading and within the page-content class; if necessary, add more paragraphs below that.
Creating an Error 404 Page
If your WordPress Theme does not include a template file named 404.php, you can create your own.
There’s no certainty that copying the 404.php template file from the Twenty Thirteen Theme would work, but it’s an excellent place to start. Because it actually calls the header and footer of the current theme, the error page you copied from the Twenty Thirteen Theme will adopt the current theme’s layout. That means you’ll have less work to do, and you might only need to tweak the message to fit your needs.
To use the 404.php template file from the WordPress Twenty Thirteen Theme:
- Copy the file /wp-content/themes/twentythirteen/404.php into the directory of your current theme.
- Then, as described in the previous section, edit the error message to present your desired error message.
If the default 404.php in your theme directory does not function, you can also:
- Copy the file /wp-content/themes/twentythirteen/404.php into the directory of your current theme.
- Then, as described in the previous section, edit the error message to present your desired error message.
If copying the default 404.php into your theme directory does not work well with your theme, you can also:
- Change the Default Theme’s 404.php template file’s header, sidebar, footer, and other codes to match the rest of the Theme’s layout.
Or
- Copy the index.php file of your current theme to a file called 404.php.
- Open that file and delete all sections dealing with posts or comments, see The Loop.
- Then, edit your 404 error message.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
