Simple wordpress function for redirect 404 error pages to homepage without plugin, right way to redirect 404 error pages in wordpress easily.
How To Redirect 404 To Homepage In WordPress
Very easy! using is_404() function and wp_redirect() function and template_redirect action we will redirect all 404 error pages to homepage in wordpress.
Function
Just copy the code and paste it in your functions.php file:
function WPTime_redirect_404_to_homepage(){ if( is_404() ){ wp_redirect( home_url(), 301 ); exit(); } } add_action('template_redirect', 'WPTime_redirect_404_to_homepage');
Now will be redirect all 404 error pages to homepage.
Note
No SEO errors with this function.
You can also read Redirect Post After Delete.
6 Comments
David
Hi Qassim
I don’t know much about 404 error pages because I had started my blogging career recently.
But somewhere I read that If any blogger or writer deleted the existing web page then the URL of that web page becomes 404 URL and that page becomes 404 page.
It is also said that Google don’t like 404 page so I checked my site whether I had any 404 page or not then I found few of the 404 error pages on my site also.
But Now after reading this post, I can easily handle these pages.
Thanks for sharing such a helpful post with us. :D
Brenda Smith
I can’t deny that you haven’t written informative article.
It is true that your article is very much helpful and informative.
As I had started my blog few months ago so I haven’t enough information about 404 error pages and that’s why, I had so many 404 errors on my blog and after reading this article, I get to know that how to deal with these not found errors.
If I am right then 404 pages are those where we don’t find any content except a 404 error message and It occurs If any writer deleted the existing content and the URL of that content remain indexed in search results.
I also heard that Google don’t like these pages so every webmaster should check out their website regularly for these errors to keep their website SEO friendly.
Thanks for sharing this article with us because It taught me that how I can handle these pages and keep my site at safer side.
John
Indeed a Great post about 404 redirection.
It is said that 404 not found pages or broken pages aren’t good for any blog because It gives bad user experience and It also affects badly in search engine rankings.
Search engine like Google never wants to redirect their users to a page which shows not found errors. Right?
So It is must to redirect these 404 pages to either another relevant page or to homepage.
I can remember when I started my 1st blog then I didn’t have any idea that on which niche I should write. So I used to write on different different topics and later deleted those articles when move to another niche.
In this way, I created so many 404 not found pages in my blog and one day, I realized that Webmaster tools is showing so many not found errors.
When I saw that, I scared because I didn’t knew about these pages at that time. Then I did research and fixed those pages.
Thanks for sharing such a wonderful tutorial.
Kanak Mehra
Very informative post, Qassim. I loved especially how you covered the way of redirecting 404 not found pages also end tips are awesome. I never tried this method before. But Thanks for explaining me this method.
Qassim Hassan
You’re welcome.
Hassan
what about plugin on wordpress.org? it’s faster or slower to function??
example 404 to homepage https://wordpress.org/plugins/404-to-homepage-littlebizzy/
thanks