Index: wp-login.php
===================================================================
--- wp-login.php	(revision 40958)
+++ wp-login.php	(working copy)
@@ -945,6 +945,15 @@
 <?php } ?>
 
 <script type="text/javascript">
+<?php
+/**
+ * Filters whether to print the call to `wp_attempt_focus()` on the login screen.
+ *
+ * @since 4.8.0
+ *
+ * @param bool $print Whether to print the function call. Default true.
+ */
+if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { ?>
 function wp_attempt_focus(){
 setTimeout( function(){ try{
 <?php if ( $user_login ) { ?>
@@ -964,15 +973,6 @@
 }, 200);
 }
 
-<?php
-/**
- * Filters whether to print the call to `wp_attempt_focus()` on the login screen.
- *
- * @since 4.8.0
- *
- * @param bool $print Whether to print the function call. Default true.
- */
-if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { ?>
 wp_attempt_focus();
 <?php } ?>
 if(typeof wpOnload=='function')wpOnload();
