A 404 error page, or for those not familiar with the term, the ‘Page not Found error’ is important to have with any website. At Blondish.net, there is an article that illustrates the importance of a custom 404 page in detail, but it is really simple.
1. You are keeping your visitor within the site and giving them an alternate way to find what they are looking for.
2. The search engines will not frown as much on your custom 404 page as you are being courteous to your user, and once again, giving them another way to find what they want on your site.
A lot of themes come with the 404.php file, but there are some that do not. In the case you are making your own theme, or if you have downloaded a freebie, then you can make your own.
1. You need to know where to get the code for the 404 page, which can easily be found in the WordPress Codex. In the case of this tutorial, it will be using the basic code.
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<h2 class="center">Error 404 - Not Found</h2>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
2. Sure, you have a 404 page that will say “Error 404 – Not Found”, but you really need your site to do something. Perhaps you should add articles that are popular or want your readers to see that may be missed. Or perhaps it was a click on an old internal link from an old blog entry, you should think about putting a search form. A search form will really help.
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
3. Edit your message to something friendly. Sometimes “Error 404 – Not Found” might be a bit shocking and make your user think they did something wrong. You could direct them to the home page of the site or as already suggested, articles you want your visitors to read.
Here is an example that is used here at Blondish.net
Oopsie! Sorry for the inconvenience.
If you were looking for something on Blondish.net, and did not find it you can contact me or use the form below to search for it. Again, apologies!
The message is allowed to be used. Just change the site name. No credit back is needed.
4. Add your recent posts. This may entice your readers to stay on the site. It is also fresh content and easier than adding featured posts (and editing them from time to time.)
<h2>Recent Posts</h2>
<ul>
<?php query_posts('posts_per_page=5');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="Permalink for : <?php the_title(); ?>"<?php the_title(); ?></a>
<?php endwhile; endif; ?>
</ul>
5. Get the search engines to find the custom 404 page. In your .htaccess file, you need to put the code:
ErrorDocument 404 /index.php?error=404
In the case your installation is not on the root of your site, but instead a subfolder, you need to make sure the folder name is added before the index.php link for the .htaccess Error Document function.
Very easy, right?
adi kurniawan says
yeah
i hate when i found 404 page
but i like the custom one
like
ops seems like you are lost
click here to go to homepage