How to Improve Your 404 Page Template in WordPress

How to Improve Your 404 Page Template in WordPress

404 errors are not good for user experience. We showed you how to get email alerts for 404 errors on your site so that you can quickly fix them. In this article, we will show you how to improve your 404 page template in WordPress, so you can create a more useful 404 page that actually help users.

How Most WordPress 404 Page Looks Like?

404 page is often the most neglected page on most sites. Often a lot of WordPress themes 404 page looks like this:

Twenty Fourteen 404 Page

This 404 page in WordPress is handled by a template file called 404.php.

If your configuration is really messed up, then the 404 page would look like this:

404 error handled by browser Neither of the above 404 pages are really useful.When a user lands on a 404 page, they’re already frustrated. Why? Because they can’t find what they were looking for.

You need to help the user find the right page. You can help make this experience better by properly conveying the error, and give them a proper course of action (i.e What to do next).

This can be done by showing them other sections of your sites they can visit, give them a way to contact you, etc.

How to Create a Custom 404 Page in WordPress?

First thing we need to do is start by creating a custom 404 page template. This can be done by editing the 404.php file in your WordPress theme. If you are editing your theme directly, then we would urge you to at least backup your WordPress theme. To make your 404 page more useful, we are going to show you how to add useful elements such as popular posts, most commented posts, recent posts, date archives, list of all categories, etc.This will allow new users to have a quick glance at what you have to offer.

Display Most Popular Posts on 404 Page

First thing you need to do is install and activate the WordPress Popular Posts plugin on your website. Upon activation, you need to add this template tag into your 404.php file where you want to display the popular posts.     <?php wpp_get_mostpopular(); ?>

Display Most Commented Posts on 404 Page

The most commented posts section also relies on the popular posts plugin we activated in the last step. Simply add this template tag where you want to display your most commented posts.

<?php wpp_get_mostpopular(“range=all&order_by=comments”); ?>

Display Recent Posts on 404 Page

There are multiple ways to display recent posts in WordPress. The easiest way is to add this template tag in your 404 template to display your recent posts.

<?php wp_get_archives( array( 'type' => 'postbypost', 'limit' => 10, 'format' => 'custom', 'before' => '', 'after' => '<br />' ) ); ?>

Display Random Posts on 404 Page

If you want to display a random list of posts in WordPress, then you can simply add this code in your 404 template where you want to display a random list of posts from your site.

<ul>
<?php 
$posts = get_posts('orderby=rand&numberposts=5'); 
   foreach($posts as $post) { ?>
        <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </li>
   <?php } ?>
</ul>

Add Monthly Archives with Compact Archives

Install and activate this plugin the Compact Archives plugin. After activating the plugin, add the following code in your 404.php file:

<p><strong>By Date</strong></p>
<ul>
<?php compact_archive($style='block'); ?>
</ul>

It will display your monthly archives like this:

Displaying monthly archives one year per row using Compact Archives

Leave a Reply

Your email address will not be published. Required fields are marked *