How to Use the WordPress  ‘login_language_dropdown_args’ Filter Hook

How to Use the WordPress ‘login_language_dropdown_args’ Filter Hook

Last Updated on August 1, 2023 by Mike Kipruto

This is a WordPress filter hook that filters default arguments for the Languages select input on the login screen.

Usage

/**
 *
 * How to Use the WordPress  ‘login_language_dropdown_args’ PHP Filter Hook
 *
 * @link https://kipmyk.co.ke/how-to-use-the-wordpress-login_language_dropdown_args-php-filter-hook/
 *
 * @param array $args The original arguments for the language dropdown.
 * @return array Modified arguments for the language dropdown.
 */
function mk_login_language_dropdown_args( $args ) {

    // Write your custom code here to modify the arguments for the language dropdown.

    return $args; // Return the modified arguments for the language dropdown.
}
add_filter( 'login_language_dropdown_args', 'mk_login_language_dropdown_args' );

For more information, please take a look at the WordPress Developer Resources: login_language_dropdown_args

Examples

How to Set Default Language to Spanish

To set the default language to Spanish, you can modify the ‘selected’ argument using the following code:

add_filter('login_language_dropdown_args', 'mk_set_default_language_to_spanish');
function mk_set_default_language_to_spanish($args) {
    $args['selected'] = 'es_ES';
    return $args;
}

How to Show Only Specific Languages

To show only specific languages in the dropdown, you can modify the ‘languages’ argument using the following code:

add_filter('login_language_dropdown_args', 'mk_show_specific_languages');
function mk_show_specific_languages($args) {
    $args['languages'] = array('en_US', 'es_ES', 'fr_FR');
    return $args;
}

How to Change the Language Dropdown Label

To change the label of the language dropdown, you can modify the modify the ‘show_option_none’ argument using the following code:

add_filter('login_language_dropdown_args', 'mk_change_language_dropdown_label');
function mk_change_language_dropdown_label($args) {
    $args['show_option_none'] = 'Choose your language';
    return $args;
}

How to Remove the “Site Default” Option

To remove the “Site Default” option from the language dropdown, you can modify the ‘show_option_site_default’ argument using the following code:

add_filter('login_language_dropdown_args', 'mk_remove_site_default_option');
function mk_remove_site_default_option($args) {
    $args['show_option_site_default'] = false;
    return $args;
}

How to Display language names in their native language

To display language names in their native language, you can modify the ‘display_names’ argument using the following code:

add_filter('login_language_dropdown_args', 'mk_display_native_language_names');
function mk_display_native_language_names($args) {
    $args['display_names'] = true;
    return $args;
}

Leave a Reply

Your email address will not be published. Required fields are marked *