Guide To Blogging

Tips and advice to get your blog up and running
December 2nd, 2007

Creating Your Own 404 Page Not Found For WordPress

Quite awhile ago I wrote a post about editing the WordPress 404 Page to make it more user friendly for your readers, within that post I explained a quick and easy way to do it if your chosen blog template already has a 404 page created.

If, however, you don’t have a 404 page as part of your blog theme then you can quickly remedy that by adding or making your own. Some themes will allow you to simply add/upload the 404 page that comes with the default WordPress theme into your new blog theme’s directory. Unfortunately though, some won’t and you need to take the extra step of creating your own.

This blog for example; earlier today when I mentioned editing 404 pages in a forum I suddenly realised that when I changed themes I no longer had an edited 404 page (it was just the standard page not found message) I wanted to quickly change that to make it more useful (and so I didn’t look quite so silly if someone tried it on the blog after reading my message :-) ).

Here’s the steps I took to quickly create a 404 page:

Download your index.php file of your chosen theme and rename it 404.php you then need to open it with notepad and make your changes (right click - open)

You’ll see a lot of gooblygook (well at least it is to me as I don’t know a great deal about all the php stuff) the most important part though will be the top of the page which is what calls your footer and sidebars etc when the page is opened. eg.

<?php get_header(); ?>
<?php get_sidebar(); ?>
<div class=”middle”>

This line below is the start of what is known as The Loop (this is for your posts etc) and is not need for your 404 page

<?php if (have_posts()) : ?>

This continues until here:

<p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
<?php endif; ?>

Everything within The Loop can be deleted and replaced with your chosen information for your 404 page. eg.

<?php get_header(); ?>

<?php get_sidebar(); ?>
<div class=”middle”>

<h2 class=”center”><b><center>OOPS! Something went wrong</center></h2><center>It seems the gremlins have been hard at work again</center>In the mean time, while I work to try and catch them and stop them from creating havoc around here, you might like to try finding the page you were after in one of the ways I’ll list below:

Below that you’ll probably have the get header get footer etc similar to the top of the page

</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

The above bold section is an example of what your 404 page could look like once completed

Once you have the page created to your satisfaction you then need upload it your your blog’s theme - wp-content/themes/chosenblogthemename

Then you can check that it all works by testing it with an incorrect url. If it looks how you want you don’t need to do anything else (always a good thing) you can edit if need be by opening your theme editor in your dashboard and clicking on 404.php, or if need be you can delete it entirely via your chosen ftp etc.

I hope all that made sense - as always I suggest you copy any files as backup in case something goes wrong

If you liked this post you can buy me a coffee :-)

3 Responses to “Creating Your Own 404 Page Not Found For WordPress”

  1. [...] Creating Your Own 404 Page Not Found For WordPress [...]

  2. Thanks for sharing it. Is there a way that we can show search form in main content area of a 404 page.

    web trac’s last blog post..Godaddy Renewal Coupon 30% off

  3. Hi, thanks for the comment

    Yes. You can add your search form just like you would any other way - just paste/write in your code wherever you want it to show up on your page.

Leave a Reply