In my previous article I explained about significance of 404 error page in website development. If you missed it, then you can read it here Create 404 Error page to decrease bounce rate on WordPress.
The WordPress 404 error page is usually custom coded, and hence it can be enhanced as per our requirements and needs. In this article we will learn how to redirect 404 error page to homepage in WordPress.
Redirect 404 error page
Below is a simple procedure to add redirection on 404 error page to homepage of blog.
- Navigate to Theme Directory and locate 404.php file.
- If found, open it in any text editor. If you couldn’t find one, then just read how to create 404.php file in wordpress.
- Copy the below code snippet, and replace it completely with existing code.
<!--?php $URL= get_bloginfo('url'); header("Location: $URL"); ?-->
- Done adding the code ? Now, save the file and upload it to server.
We are done!
Adding the above code, will redirect any visitor to Blog’s homepage, if encountered any error or broken links. In a way it can be modified to set custom link as well. only thing is you need to edit line number 3 and add the custom like after “Location: http://www.thecreatology.com”.
If you think its complex then you can hire me for this virtual assistance.