Every website got a 404 not found error page. It’s a part of every website. Last day, one of our users asked how to redirect WordPress 404 error to homepage. In this post, we are going to show you how can you do it in the right way.
Last time, we have shown you how to check broken links in WordPress. If you are not properly redirecting your broken links, the users will see a 404 page. By redirecting the 404 errors to the homepage, you will be able to keep your website free from not found errors.
How To Redirect WordPress 404 Error To Homepage
Typically, there are 2 simple methods available.
- By creating a 404.php file
- Using a plugin
Below, we are going to cover them both. From those options, you can choose your preferred method.
First of all, you need to go to the theme folder. Create a file named 404.php. Now, copy the below code, paste on it and save the file.
If your theme got already a 404.php file, you need to edit it with the below code.
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
We highly recommend you create a child theme and making all edits on that. The code will redirect all 404 entries to your website’s homepage.
You need to install the All 404 Error to homepage plugin.
Now, activate the plugin.
Upon activation, you can see the plugin settings under your WordPress settings. Enable the plugin, enter the web address that you need to send every 404 entries and update the options.
From now on, your 404 users will get redirected to the specific web address.
You don’t need to use both code and plugin at a time. We recommend you use the code on your website. If you want to redirect the 404 entries to a specific URL, you may want to consider the plugin.
We hope you found this tutorial helpful and enjoyed the read. If you did, please consider sharing this post with your friends on social media. From our blog, you can get more related guides and reviews.