Using WordPress ‘get_locale()’ PHP function

The get_locale() WordPress PHP function retrieves the current locale of the website.


To use the get_locale() function, simply call it without any parameters:

$current_locale = get_locale();
echo "The current locale is: " . $current_locale;


  • None

More information

See WordPress Developer Resources: get_locale()


Display the current locale

This example retrieves and displays the current locale on the website.

$current_locale = get_locale();
echo "The current locale is: " . $current_locale;

Set the monetary locale

This example sets the monetary locale using get_locale() and setlocale() functions.

setlocale(LC_MONETARY, get_locale());
$my_local_settings = localeconv();
if ($my_local_settings['int_curr_symbol'] == "") {
    setlocale(LC_MONETARY, 'en_US');

Load translation file based on current locale

This example loads a translation file based on the current locale using load_textdomain().

$current_locale = get_locale();
load_textdomain('my-text-domain', "/path/to/translations/{$current_locale}.mo");

Change the current locale using a filter

This example changes the current locale using the ‘locale’ filter.

function change_locale($locale) {
    return 'fr_FR';
add_filter('locale', 'change_locale');

Display date in the current locale

This example displays the current date formatted according to the current locale using strftime().

setlocale(LC_TIME, get_locale());
echo strftime('%A %e %B %Y');