How to Hide Errors on WordPress
When a visitor attempts to access a page on your WordPress site that doesn't exist, they are sent to the 404 page of your blog. Typically, a 404 page has a large title stating "404 -- File Not Found" along with a short message explaining the situation. This can be annoying for visitors, and might seem unprofessional on commercial sites. There are two ways to hide 404 errors: the first is to turn the 404 page into something more useful and the second is to redirect it to another page on your site.
Instructions
-
Modifying the 404 Error Page
-
1
Log in to your WordPress admin panel. Click "Appearance" and then "Editor." Look for 404.php on the list of files on the right -- usually it will be right at the top. Click it to open it into the editing pane.
-
2
Modify the HTML code on this page. You might want to change the title to something more friendly, such as "We're sorry! We can't seem to find the file you're looking for." Underneath this, you can then add some additional features. Some websites take the opportunity to tell the visitor more about the site and provide links to some of their best content. Other websites embed small HTML games into the 404 page for a novel error experience.
-
-
3
Click "Update File" when you're done. Your visitors will now be presented with a more palatable 404 screen.
Redirect the 404 Page
-
4
Log in to your WordPress admin control panel. Click "Appearance" and then click "Editor." Click 404.php from the list on the right side of the screen, which will bring it into the central editing area.
-
5
Select all the code in the screen and copy it. Open up a text editor such as Notepad and paste the code into it. Save this file to your computer.
-
6
Go back to the WordPress admin screen and delete all the code in the 404.php file. Now that you have a backup copy, you can replace the old version should you ever need to do so.
-
7
Paste the following code into the now-empty 404.php file:
<?php
header("Status: 301 Moved Permanently");
header("Location:http://www.ChangeThis.com");
?>
Change the URL to the location you want the 404 page to direct to. For example, you might use your blog's home page. Click "Update File" when done.
-
1
Tips & Warnings
You can test your changes by going to a page that doesn't exist, for example yoursite.com/uhuhuhuh. If the changes you made are not taking effect, return to the Theme Editor and check that the code has been entered correctly and that the changes were saved.
References
- Photo Credit Thinkstock Images/Comstock/Getty Images