apply_filters( ‘locale’, string $locale )

Filters the locale ID of the WordPress installation.

Parameters

$localestring
The locale ID.

Source

return apply_filters( 'locale', $locale );

Changelog

VersionDescription
1.5.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    You can leverage this hook to force the language of your admin dashboard, however, you need to call it from a plugin and not from your theme, by the time WordPress gets to loading your theme it’s too late.

    <?php
    /*
    Plugin Name: English Only Admin
    Plugin URI: http://your-domain.com
    Description: Force English (en_US) in the WordPress Admin
    Version: 1.0
    Author: You
    Author URI: http://your-domain.com
    Text Domain: englishonlyadmin
    */
    
    // prevent direct access
    if ( ! defined( 'WPINC' ) ) {
        die;
    }
    
    if ( ! function_exists( 'uniquePrefix_force_english_only_admin' ) ) {
        /**
         * Override locale for admin to force English (en_US).
         *
         * @param string $locale Current locale.
         *
         * @return string English (en_US) locale if in Admin, configured locale otherwise.
         */
        function uniquePrefix_force_english_only_admin( $locale ) {
            // detect when we are in the admin dashboard and force english
            if ( is_admin() ) {
                $locale = 'en_US';
            }
    
            return $locale;
        }
    
        add_filter( 'locale', 'uniquePrefix_force_english_only_admin', 1, 1 );
    }
  2. Skip to note 4 content

    Example migrated from Codex:

    An example of changing the locale language based on the $_GET parameter of the URL.

    <?php
    add_filter( 'locale', 'set_my_locale' );
    
    function set_my_locale( $lang ) {
       if ( 'gl' == $_GET['language'] ) {
          // set to Greenlandic
          return 'ka_GL';
       } else {
          // return original language
          return $lang;
       }
    }
    ?>

You must log in before being able to contribute a note or feedback.