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.
I had a problem with my Hostgator 404 page they were showing Hosting Ads for my 404 pages they were using my referral link in the 404 page but the people visiting my site were looking for help with their computers or something like that they were not looking to buy a hosting package. Another thing some may think that a funny 404 page with a caption is cool I find them as useless as normal 404 pages. With a 404 page if you are not going to redirect to your homepage at least include a search box or some links that may interest the visitor otherwise they will just click the back button on their browsers.
I agree with you Roezer, 404 error pages are mandatory and one should optimize and enhance it for better blogging. 🙂
I had a blog and recently I found virus on it,So hosting people ask me to remove all my content and rebuild it. This is very helpful to me as now I can redirect my visitors from previous backlinks to home page.
Thank you.
i love to use this trick to redirect the uncovered link to home page, but it good for seo?
Answer to your question, Redirecting 404 Error Page is good or bad for SEO ? has always been mystery for people, including me. But my insights about SEO says, it is not good to redirect 404 error page as if any visitor open broken link or wrong URL then visitor will not realize if there was an erroneous URL and will be redirected to homepage. Which visitor may not like or face ambiguous situation, hence decreasing SEO score.
Also, according to Google SEO Basics, it is mandatory to have a 404 Error Page in your website. No matter what you type in that! 😛
I hope it helps you to get out of this dilemma or just join the confused club. Cheers! 😉
Hi i used your trick but its not working on my wordpress blog.
Broken urls are not redirecting to home page…
I always redirect all 404 to homepage for smaller website:
https://wordpress.org/plugins/404-to-homepage-littlebizzy/
And no, never got any SEO problems or Google issue. Actually, it’s helping my rankings.