How to edit your WordPress theme to redirect 404 error page back to the homepage?

posted in: WordPress | 0

When someone accesses to a page which is no longer available on your site or you accidentally type in one of the page/file/… in your blog, the 404 error page will popup; if the reader see this page, most of them get out right away, but you want to keep them on your site a little bit longer so how to do. How to get them seeing your other pages especially your ad placing like Google Adsense. Here are steps by steps how to edit your WordPress blog theme redirecting 404 error page to your blog homepage.

Example: When I access one of my old page named “how to make money” on my www.allchit.com blog, http://www.allchit.com/how-to-make-money, the following screen with
“Nothing Found”
“Sorry. The Page of File you were loading for was not found.”
message pops up.
404error_howto_redirecttohomepage

What am I going to do now? Here are steps by steps how to do solving this problem.
Step #1: Login your Administration screen and then click the drop down where “Appearance” is located (on the left side of the screen). Next, click “Editor“.
404error_howto2

Step #2:  Now, your theme’s stylesheet (style.css) appears.  Next, click on “404 Template (404.php)” from the right side of the screen  and under the “Templates” section.
404error_howto3

Step #3:  The important stuffs are right here in this step.  Locate “<?php get_header(); ?> inside 404 Template (404.php) screen and then, add the following code above it.
<?php
header(“HTTP/1.1 301 Moved Permanently”);
header (“Location: /”);
?>
404error_howto4

Step #4:  Here is how it’ll look like.
404error_howto5
Now, just click “Update File” at the bottom of the 404 Template (404.php) code screen to save whatever you just changed.

Step #5:  Let try loading “how-to-make-money” page again.
 http://www.allchit.com/how-to-make-money 
404error_howto_result_wpsurgery
See the page “how-to-make-money” which is no longer in www.allchit.com blog redirect the reader back to the homepage “wpsurgery.com”

Done!  It’s perfect now and no longer getting trouble with Google Adsense crawling.

(Visited 410 times, 1 visits today)

Leave a Reply