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.


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 );
add_action('template_redirect', 'WPTime_redirect_404_to_homepage');

Now will be redirect all 404 error pages to homepage.


No SEO errors with this function.

You can also read Redirect Post After Delete.