diff --git a/src/wp-login.php b/src/wp-login.php
index e02208ae56..363b7bfc32 100644
--- a/src/wp-login.php
+++ b/src/wp-login.php
@@ -38,7 +38,7 @@ function login_header( $title = 'Log In', $message = '', $wp_error = '' ) {

 	add_action( 'login_head', 'wp_login_viewport_meta' );

-	if ( empty( $wp_error ) ) {
+	if ( ! is_wp_error( $wp_error ) ) {
 		$wp_error = new WP_Error();
 	}

diff --git a/tests/phpunit/tests/http/getHttpHeaders.php b/tests/phpunit/tests/http/getHttpHeaders.php
index ccb6b4f545..d4a03a82e1 100644
--- a/tests/phpunit/tests/http/getHttpHeaders.php
+++ b/tests/phpunit/tests/http/getHttpHeaders.php
@@ -50,6 +50,15 @@ class Tests_HTTP_GetHttpHeaders extends WP_UnitTestCase {
 		wp_get_http_headers( 'does_not_matter', $deprecated = true );
 	}

+	/**
+	 * Test to check if login_header is getting error argument.
+	 */
+
+	public function test_wp_get_http_headers_login() {
+		$result = login_header( 'Log In', '', 'Test.' );
+		$this->assertWPError();
+	}
+
