What is a 404 error page
A 404 page is what shows up if you click on a link that doesn’t work (anymore) or make a mistake by typing in an Url. WordPress displays this page automatically to each visitor that tries to access a Url that doesn’t exist.
How to make a custom 404 page for your WordPress blog
This will only work for self-hosted blogs, not for free ones on WordPress.com!
First of all I want to thank BinaryMoon for his very helpful post that finally pointed me in the right direction!
I promise, I will not bore you with my long journey full of failures, instead I will show you an easy way to add a custom error page to your WordPress blog. You can follow the instructions to create whatever error page you want. I just needed one for my 404 error page, because the default page was rather dull, boring and not very helpful for my readers. For the ones of you that are not very savvy with code I will provide a custom template at the end of this post. That you can just copy, paste and adapt to your needs.
Why you need a custom error 404 page
Why bother at all to make a custom error 404 page for your blog? Try out the default page on your own blog or site and see how useful or useless it is for your readers and for your site.
Chances are that
- The default error page of your web host is used, often with advertisement and promotional offers on it.
- Or that your default 404 error page shows something like “Oops, what you are looking for is not here.” and a lot of empty space…
Neither of these possibilities helps your readers and / or your site. A good custom error page keeps readers on your site by providing them several possibilities to find what they are looking for and can be also a source of income for your web site by displaying a Google search box, banners or other kinds of ads. Have a look at my
custom error page (there is none anymore because I use now Link Juice Keeper on this blog, for more information about this great, free!, plugin see this new blog post: http://sheseo.com/best-wordpress-plugins-2011-2012/
I choose to display a Google search box and a list of my most recent posts. That should keep visitors busy 😉
How to create a custom error page
First check if there is already one in the main folder of your current theme. You can check this by going to Dashboard>Appearance>Editor. Look here for a file called “404 Template (404.php)” or similar. Select all the code and copy it into a new file on your desktop and save.
Use either Notepad or OpenOffice to do this and avoid Microsoft Word, as it will ad extra code to your file! Now that you have a a back-up copy of your 404 error page file, you can either edit it directly in your dashboard or work on a copy on your computer. After you have finished it, you just replace all the code in the “404 Template (404.php)” in your dashboard with the new version, click “update file” and check that it functions well, by trying out a non-existing url on your web site.
If you don’t have a custom “404 Template (404.php)” in your theme folder, just create a new file, called 404.php with the code you would like to use and upload it via ftp or cpanel to the folder of your current theme. It will then automatically show up next time you open Dashboard>Appearance>Editor. I had to go this route as Atahualpa, the theme I use, doesn’t have a own error 404 page, it relies on the default one in WordPress.
If you don’t have an editor that can save *.php files, here is a little workaround 😉 Open a new document in NotePad (Windows) or TextEdit (Mac) and save it as “404.php” INCLUDING the quotation marks on your desktop. Close the document and than rename it to 404.php, deleting the quotation marks. And it will be a valid *.php file 😉
All this might seems intimidating at first, but trust me, if I managed it, you will do also. Below a commented custom 404 error page template that you may use and adapt to your personal needs. Just replace the words I wrote with your own words and codes. Any more questions, suggestions? Anything I got wrong? Just leave a comment 😉