WordPress will typically redirect broken links and missing pages/posts to a 404 error page (404.php) that displays the appropriate error message for a page that could not be found. Sometimes instead of utilizing a 404 error page it's better to redirect all 404 errors directly to your WordPress home page, this of course comes down to personal preference. In this tutorial we will teach you how to use PHP to redirect all 404 errors to the home page in WordPress.
Open your 404.php page if you already have one, if not then create a new PHP file and name it 404.php. Delete any and all code that is currently inside the 404.php page, then copy and paste the PHP redirect code below. After uploading the PHP file to your server it's usually always a good idea to go ahead and refresh your permalinks. Open your site and test a broken link, all of your 404 errors should now be redirecting to your WordPress home page.