404 Error pages in WordPress – a few simple ways to customise your 404 Page

A quick guide to the 404 Error Page and WordPress. This post takes a quick look at the 404 Page and will show you how you can do some basic customizations to your 404 Page in WordPress.

The 404 Page – what is it?:
We have all seen them, the 404 page is the page that you see on a website when you request a page that no longer exists or cannot be found.

The 404 is an HTTP status code, and is probably one of the most recognizable errors on the internet and is understood by pretty much everyone regardless of your technical background or understanding.

They often look like this:
404 pages

If you aren’t sure how to view your 404 page then just type in a random url for a page that you know doesn’t exist on your site, maybe something like: www.yoursite.com/random111. That should trigger your 404 page.

Can you make 404 Pages better?:

In recent years, websites have gotten smarter about how they handle 404 errors – instead of showing users the bland, dull, and impersonal error page of the Web Server, why not use this opportunity to reduce bounce rates, or to make your user smile, or to drive them to more useful information, or to offer a solution etc…….basically anything is better than just a “Error 404: file not found” message.

This is a great (and short – only 4.08 minutes) TED talk from Renny Gleeson about the 404 Page, where he gives his own views on the opportunities of a good 404 page, and looks at some real world examples. Hopefully something here will inspire you to play around with your own 404 pages.

How can I customize my own 404 Error Page in WordPress?:

The good news is that most modern WordPress themes come with a 404 page (you will see a 404.php file in your website directory) that you can find easily in your ‘Editor’ in WordPress and edit.

  1. Go to ‘Dashboard
  2. Click on ‘Appearance’
  3. Click on ‘Editor’

From there you should be able to see your 404 Error template in the ‘Templates’ section on the right-hand side. Simply click on it to open it and edit it. You should be able to quickly spot the text that your current 404 page displays, and it is a simple task to change this – just type the new text that you want to appear and press ‘save’.

Here is what mine looks like below, with the text that I changed highlighted in the box.

404 page in wordpress

If your WordPress 404 page already has a search box and you are mostly happy with the layout and you just want to tweak the text a bit, then you can do that via this method.

Adding ‘Recent Posts’ or other content your 404 Page:

We have shown you how to change the text on your 404 Error Page above, but what if you want to add some extra features or provide links to other content on your site?

For our 404 Page we tweaked the text, and then added a few automated links to other posts and articles on our site – it won’t win any design awards, but at least it provides extra choices for any users landing on our 404 error page.

You can see it below:

New 404 Page

So how did we do it?:
We have added 2 pieces of content to our 404 page that updates itself automatically – ‘Popular Posts’ and ‘Recent Posts':

1: How to show Popular Posts:
Showing your popular posts (ordered by by page-view in our case) is a popular content module to show on a 404 page – after all, you may as well show your most popular content.

In order to do this you will need to install the WordPress Popular Posts plugin. This is a decent plugin that keeps track of your most popular content, and you can configure it to show popular content in the last 24 hours, 7 days, 30 days, or all time.

Once you have the plugin installed and activated, then just go to your 404.php page in the Editor add the following code in to the page, where you want it to appear:

<?php wpp_get_mostpopular("stats_views=0"); ?>

Note: We set the ‘stats-view’ to equal 0 as we didn’t want to show the number of page-views next to each entry (our numbers are still pretty low, so we didnt want to highlight that too much ;)). You have complete control over this, so if you want to show page view numbers then you can set ‘0’ to ‘1’.

2: How to show Recent Posts:
We also chose to show ‘recent posts’, and you can do this easily by simply adding the following code to your 404.php page:

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

Note: You can change the number of posts to show here by changing the ‘limit’ number. We have ours set to 5 (‘limit’ => 5,), but this could be any number that you want.

In addition to the Recent Posts and Popular Posts, we added a few header tags, line-breaks, and our final code looked like this – you can see the bits we added in bold text:


<?php
/**
* The template for displaying 404 pages (Not Found).
*
* @package Generate
*/

get_header(); ?>

<div id="primary" <?php generate_content_class(); ?>>
<main id="main" <?php generate_main_class(); ?> itemprop="mainContentOfPage" role="main">
<?php do_action('generate_before_main_content'); ?>
<div class="inside-article">
<?php do_action( 'generate_before_content'); ?>
<header class="entry-header">
<h1 class="entry-title" itemprop="headline"><?php echo apply_filters( 'generate_404_title', __( 'Oops! That page can&rsquo;t be found.', 'generate' ) ); ?></h1>
</header><!-- .entry-header -->
<?php do_action( 'generate_after_entry_header'); ?>
<div class="entry-content" itemprop="text">
<p>
<?php echo apply_filters( 'generate_404_text', __( 'Sorry! It looks like nothing was found at this location, we probably moved something or screwed up.... Maybe try one of the links below, or maybe a search?', 'generate' ) ); ?>
</p>
<?php get_search_form(); ?>

<br>
<br>
<h3>Popular Posts</h3>
<?php wpp_get_mostpopular("stats_views=0"); ?>

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

<!-- .entry-content -->

<?php do_action( 'generate_after_content'); ?>
</div><!-- .inside-article -->
<?php do_action('generate_after_main_content'); ?>
</main><!-- #main -->
</div><!-- #primary -->

<?php
do_action('generate_sidebars');
get_footer();

There is lots more stuff that you can do with your 404 page. We intend to add some images to ours soon and generally make it look a bit nicer, and we will share that on the blog as soon as we do it.

How to turn comments off on a WordPress Home Page (or any static page)

This is a post for WordPress newbies who still need a bit of help in configuring some of the basic settings on WordPress when setting up their first websites or blogs.

Specifically, this post will show you how to turn ‘comments’ off on your Homepage, or indeed, any static page created in WordPress.

WordPress is sociable by default – the ability for a visitor to comment on your blog or your pages created in WordPress is the standard setting. And this is great, it promotes discussion, and useful comments all add to the richness and value of your subject material. Blogs are meant to be sociable, right?

However, sometimes you just want to create a great looking website with WordPress and you don’t want your homepage to stretch on into infinity with comments making it look like a blog post. Sometimes you just want a simple homepage that simply states your offer or gives the user some key pieces of content that they can use to start exploring your website with.

A common use case I have is using WordPress to create a micro-site, and I create a custom page in WordPress for the homepage and then have the blog functionality linked as a part of the sub-nav or header. The main homepage then becomes a permanent static page.

So how do I turn the Comments off in WordPress?

So here is the good news – its is easy to turn comments off on a specific WordPress page.

  1. Once you have created your page, then simply go to your WordPress dashboard and click on the ‘Pages’ section in the left-hand nav bar.
  2. Hover over the name of the page that you want to turn the comments off on, you should see the ‘Quick Edit’ option appear – click on it
  3. On the right hand side, above the ‘status menu’ you should see a check-box called ‘Allow Comments’. Uncheck it, and it will prevent comments from being added to the page.

A picture tells a thousand words, so check out the image below to see how you turn off comments on a specific WordPress page:

how to block comments on wordpress pages

How to find an unclosed Div tag

This post is about making a change to your WordPress site and leaving an div tag open…and finding out that it screws up the layout of your website or blog….often pushing the sidebar down to the footer of the page where WordPress is concerned.

So, you have installed WordPress, found a theme that ticks most of the boxes and has most of the features that you are after for your blog or website.

You have got the site into shape, you have some content up, you have allowed it to be found by search engines…..you are pretty much ready for the world.

There are just a few things that you want to do in order to add some personal touches that involve opening the WordPress Editor (Appearance > Editor). Maybe you wanted to add something to the footer of all your posts, maybe you wanted to change the sidebar….whatever it was it involved you making a minor tweak to the code of your website. Maybe you just tried to add a piece of code to one of your posts and didn’t even open the WordPress Editor at all.

Anyway, you made your changes and hit ‘save’ or ‘publish’.

You go back you admire your work but…….crap, the whole website is screwed up. What happened?

WTF! My WordPress sidebar has fallen to the footer of the site?:

I have done this many times – made a quick change to a blog (usually late at night when I don’t have the time, will, or energy to subsequently fix it) and found that I have f**ked something up.

One of my common issues is making a change and then finding that my WordPress sidebar is no longer where it should be, and has fallen down to the bottom of the website, so it is now found below the footer.

This can be caused by a few things – one common example is trying to insert an image into a post that is too large. For example, trying to force a 2000px image into a post with a fixed width of 600px means that something will break – usually your template.

My most common error is leaving an open div tag in a post or in the actual theme after using the WordPress Editor.

Check the screenshot below to see an example of an unclosed div tag:

example of an unclosed div tag:

Everytime my Sidebar slides down the page it is 99% of the time caused by an unclosed div tag.

So how do you fix it?:

Finding an unclosed tag can be a pain, especially if you don’t really remember when you might have introduced the issue. You can either wade through your html/markup looking for errors, or you can make your life easier by using some free automated tools to do the job for you.

There are a few tools that I use to check for unclosed div tags, in fact, it is good practice to use these tools for checking your site for any markup errors and to ensure that your code/markup is valid.

The DIV Checker (http://www.tormus.com/tools/div_checker)
A simple, and free tool for checking your div tags. If you want to ensure that every div tag in your website has a corresponding closing tag, then simply enter your url, click ‘go’ and you will get a simple report back of any issues with your div tags. This tool has saved me multiple times in the past.

The W3C Mark-Up Validator (http://validator.w3.org/):
This validator checks the markup validity of Web documents in HTML, XHTML, SMIL, MathML – simply enter the url of your website into the site, press a button – and you get a list of any invalid markup that you should be fixing.

Running a check on your site using The W3C Mark-Up Validator is awesome, but if your site is complex, then it might still be tricky to find an unclosed div tag, so if that is the case then use the first link above to locate the div.

40 WordPress Optimisation Tips

Check out the slideshow below from Joost de Valk that he delivered at WordCamp Ireland recently – it’s a fantastic list of 40 core optimisation tips that all WordPress users should implement on their sites and blogs.

If you want to skip the intro and get straight to the optimisation tips for WordPress then start at slide 29.

Why is my WordPress blog not indexed?

Another very basic post, but if you are brand new, and I mean ‘brand new’ to wordpress it will hopefully save you some time.

In your early days of experimenting with WordPress you may wonder why your blog is not indexed in any of the search engines. Indexing can take time, but one of the first things you should check is whether your blog is even visible to search engines.

Annoyingly, when you first install WordPress it automatically sets your blog default as “I would like to block search engines, but allow normal visitors”. So no matter how kickass your blog is, or how unique your content is, it won’t get indexed in any search engines.

The good news is that this is easy to change. When you are satisfied that you are happy with the content on your blog and you are ready to unleash it on the world, simply follow the steps below to make your blog visible and accessible to search engines.

  1. From your WordPress dashboard go to ‘Settings’ (usually found in the bottom left section of your dashboard), and click on the ‘Privacy’ link.
  2. On the ‘Privacy’ page you will see 2 radio buttons under a title that says ‘Blog Visibility’. If you have just installed WordPress then you will notice that the “I would like to block search engines, but allow normal visitors” will be selected. Simply change this by clicking on “I would like my blog to be visible to everyone, including search engines (like Google, Bing, Technorati) and archivers”
  3. Click Save

Told you this was a simple, and very basic level post – but this is an easy thing to overlook for newcomers to WordPress. Hope it saves you some frustration.