When someone access a certain page on your site without successful like the page has been move or no longer there, in general, the 404 error screen appears. Neither you nor your readers like this. Instead of showing a blank page with “404 Error”, you can do something else more interesting and your readers love it too.
Here is how to do. There are couple ways to do.
- Adding code to 404 Template in WordPress site’s administration screen.
You can add couple lines of code to your 404 template page in your theme. This is done just by login your administration screen, then go to Appearance -> Editor -> 404 Template (404.php), add the codes and then save the file.
- There is an alternative way to create 404.php without accessing your WordPress site administration. That’s creating a 404.php in your site hosting server.
That’s very much to do, however, if there is no such a 404 Template (404.php) in your WordPress theme, so what should you need to do? Not very headache as you thought, you can do it just in seconds. The way is very simple, just login your site hosting server, go to your file directory and then your site directory. At your site directory, go to wp-content -> themes and click on the folder name of theme which you are using. Next, you have to do is creating a new file and name it as “404.php”.
You can add the codes here if we want to, otherwise, you can do it at your WordPress site administration screen like I mentioned in step #1.
The codes need to add in 404 Template (404.php) are
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
You can see other alternative ways redirecting 404 page at How to redirect 404 pages to homepage in WordPress?.
Note: the above codes redirect 404 error screen to your site homepage.
See you next post.