Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#40301 closed enhancement (fixed)

New filter to disable auto-focus on the login screen

Reported by: afercia's profile afercia Owned by: afercia's profile afercia
Milestone: 4.8 Priority: normal
Severity: normal Version:
Component: Login and Registration Keywords: has-screenshots has-patch
Focuses: ui, accessibility Cc:


On the login screen, wp_attempt_focus() tries to auto-focus the login input fields:

By doing so, anything that comes before the input fields (e.g. the logo) will be "skipped" for keyboard users and screen reader users. While this may make sense when the login screen is the default one, it can be confusing when the login screen is customised.

Using filters and actions, plugin authors can heavily customise the login screen, adding any kind of content before the login default fields (including additional form fields). In this case, skipping all that content wouldn't be so ideal.

There are hacky ways to avoid the call to wp_attempt_focus(), like setting again the global $error and as far as I see, people are already doing that (just googled a bit and found some use cases). I'd propose to just add a more standard way to don't print out the call to wp_attempt_focus().

Worth noting the auto-focus will still work on other wp-login.php views like, for example, the lost password one. It probably makes sense to still have auto-focus where the users task is so specific.

It will also still work when there are error messages, because it is called by wp_shake_js(). For example, when entering a wrong password, I'd say it still makes sense to focus the password field.

In these two cases, I'd avoid any change. The filter should work just on the initial login screen.

Attachments (2)

40301.diff (778 bytes) - added by afercia 7 years ago.
Local Dev No Focus on WP Login.png (23.9 KB) - added by lukecavanagh 7 years ago.
Local Dev Autofocus not being set in Chrome

Download all attachments as: .zip

Change History (13)

7 years ago

#1 @swissspidy
7 years ago

Sounds like a duplicate of #30023 to me. I'd love to fix it because the bug mentioned in that ticket is annoying.

#2 @afercia
7 years ago

  • Keywords has-patch added

Yep I've seen that ticket :) To me, it sounds more related to a (very annoying) Chrome specific behaviour.

40301.diff adds a new filter which defaults to true. Using it would be as simple as:
add_filter( 'enable_login_autofocus', '__return_false' );

Also removes a space in a doc-block.

Last edited 7 years ago by afercia (previous) (diff)

#3 @lukecavanagh
7 years ago


Patch applies cleanly and using the filter works as described and autofocus was not set in Chrome, when defined.

7 years ago

Local Dev Autofocus not being set in Chrome

This ticket was mentioned in Slack in #accessibility by afercia. View the logs.

7 years ago

#5 @afercia
7 years ago

  • Milestone changed from Awaiting Review to 4.8

Discussed in today's accessibility meeting, moving to 4.8 as something to address maybe together with #30023.

This ticket was mentioned in Slack in #accessibility by afercia. View the logs.

7 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.

7 years ago

#8 @afercia
7 years ago

  • Keywords needs-dev-note added
  • Owner set to afercia
  • Status changed from new to assigned

Adding the keyword needs-dev-note for the new filter.

#9 @afercia
7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 40652:

Login and Registration: Add a filter to disable the initial auto-focus on the login screen.

Fixes #40301.

This ticket was mentioned in Slack in #core by pbiron. View the logs.

7 years ago

#11 @afercia
5 years ago

  • Keywords needs-dev-note removed
Note: See TracTickets for help on using tickets.