This post will cover how to redirect 404 to homepage in WordPress.
It is quite simple. All WordPress installations do have 404 error page built-in with most of the themes however at times the owner of the website or even the users do not like to be on any error page.
In such case, here are the steps outlined for you to give seamless experience to your users by redirecting any error page to the home page.
Login to your dashboard.
Go to “Apperarance” -> “Editor” -> 404.php
Copy the code below in 404.php file and you’re done.
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
The code above tells the browser that the page a visitor is looking for no longer exists and hence the visitor is redirected to the homepage.