How can I change login error messages on WordPress?

This code snippet replaces the standard error messages like ‘Incorrect username or password’ with a custom message shown on the WordPress site, when a user tries to log in with incorrect login credentials.

function ts_custom_login_error_message($error) {
    // Your custom error message
    $custom_error_message = "Oops! Something went wrong. Please check your credentials and try again.";

    // Replace the default error message with your custom message
    return '<strong>' . esc_html($custom_error_message) . '</strong>';
}

add_filter('login_errors', 'ts_custom_login_error_message');