Introducing new language switcher on the login screen in WP 5.9

Edited on December 21, 2021 after [52404].

Edited on January 3, 2022 after [52432]: two filters were renamed.

Edited on January 4, 2022 after [52435]: the dropdown filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. was renamed.

Since WordPress 4.9, it’s possible to control the language of the login screen using the wp_lang query variable (example: wp-login.php?wp_lang=fr_FR). This is a hidden feature that was only used by the interim login modal.

WordPress 5.9 introduces a new language switcher available on the login screen. This dropdown allows users to use the login screen, the password reset screen, and the registration screen in their own language.

Please note that the language list in the dropdown is based on the currently installed languages of the WordPress installation. To install a new language, websites administrators can use the language selector available on Settings > General. Go to site languages drop down, select a language to install and save changes. This installs and switches the site language, you can switch back if you do not want that as the default language.

Filters default arguments for the Languages dropdown

The hook login_language_dropdown_args can be used to filter the default arguments passed to the languages dropdown displayed on the login screen, using an array of arguments for the Languages select input. Here are the default parameters of the $args parameter:

$args = array(
	'id'                          => 'language-switcher-locales',
	'name'                        => 'wp_lang',
	'selected'                    => determine_locale(), // Use the current locale by default.
	'show_available_translations' => false, // Do not show languages that are not installed.
	'explicit_option_en_us'       => true, // Use an explicit value of the 'en_US' option instead of an empty value.
	'languages'                   => $languages, // Contains the list of installed languages.
);

For example, on a website with several languages installed, only show fr_FR and de_DE in the dropdown:

function wporg_filter_login_language_dropdown_args( $args ) {
	$args['languages'] = array( 'fr_FR', 'de_DE' );
	return $args;
}
add_filter( 'login_language_dropdown_args', 'wporg_filter_login_language_dropdown_args', 10, 1 );

Remove the Language dropdown entirely

If you want to remove the Language dropdown entirely, you can use the login_display_language_dropdown filter.

Usage example:

add_filter( 'login_display_language_dropdown', '__return_false' );

Related tracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. ticketticket Created for both bug reports and feature development on the bug tracker.: #43700. See also [52404], [52432]

Props @hellofromtonya and @mkaz for proofreading.

#5-9, #dev-notes