When coding a one page site, you might not have the time to create a custom 404 page. In which case, you might as well redirect the 404 page to your site’s homepage. In this article, we will show you how to redirect 404 page to home page in WordPress.
All you have to do is open your 404.php file in your theme’s folder. If it doesn’t exist, then create a blank php file. Paste the following code in there:
2 header(“HTTP/1.1 301 Moved Permanently”);
3 header(“Location: “.get_bloginfo(‘url’));
That’s all. Now when a user hits a 404 page will be redirected to the homepage.
Note: This should be used in very specific cases. In most other cases (i.e blogs, portfolios etc), you should track your 404 pages and redirect them appropriately.