WordPress 404 Redirect to Home

To redirect 404 error to homepage you may add the little snippet code to your functions.php

/**
 * WordPress 404 Redirect to Home
 */
function yourthemename_redirect_404() {
    global $wp_query;
    if ( $wp_query->is_404 ) {
      wp_redirect( get_bloginfo('wpurl'), 301 );
      exit;
    }
}
add_action( 'template_redirect', 'yourthemename_redirect_404', 1 );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.