WordPress Redirect Visitor On 404 Error

WordPress shows a 404 page when visitor navigate to a non existent page. To redirect visitor to a specific page, say home page when visiting non existent page, edit functions.php file in your themes folder, then add following code to it.

function redirect_404_to_page() {
    if( is_404() ) {
        header( "Location: https://your-domain.tld/page/" , true, 404);
        exit;
    }
}
add_action( 'template_redirect', 'redirect_404_to_page' );

Back to WordPress

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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