WordPress: Optimizing 404 Page Not Found page

Generally the wordpress 404 page contains one or two sentence saying that the page is not found. But you can make it more user friendly. Instead of just writing plain text about page not found, we can display archive list and a search form. In this way, the visitor can search or browse your website instantly. This is a nice way to keep your visitors within your site.

Copy the following code into 404.php file of your theme. With this change, you will be able to see search form and archive list in 404 page of your site.


<?php get_header(); ?>

    <div id="content">

    <div class="post">

    <h2 class="title">Cannot find the page you're trying to reach..</h2>

        <div class="entry clearfloat">
            Use the search form below to find your article or post or browse our latest articles to read something more interesting.
            
            <form class="find" method="get" action="<?php bloginfo('url'); ?>/">

                    <input size="40" type="text" value="<?php the_search_query(); ?>" name="s" class="findfield" />
                    <input type="submit" value="Search" class="findsubmit" />

            </form>
            

            <h3>Yearly Archive</h3>
            <ul><?php wp_get_archives('type=yearly&show_post_count=1'); ?></ul>
            <h3>Monthly Archive</h3>
            <ul><?php wp_get_archives('type=monthly&show_post_count=1'); ?></ul>
            <h3>Category Archive</h3>
            <ul><?php wp_list_cats('sort_column=name&optioncount=1') ?></ul>
            <h3>Posts Archive</h3>
            <ul><?php wp_get_archives('type=postbypost') ?></ul>

        </div>

    </div>

    </div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Thanks.