get_locale()

Retrieves the current locale.


Description Description

If the locale is set, then it will filter the locale in the ‘locale’ filter hook and return the value.

If the locale is not set already, then the WPLANG constant is used if it is defined. Then it is filtered through the ‘locale’ filter hook and the value for the locale global set and the locale is returned.

The process to get the locale should only be done once, but the locale will always be filtered using the ‘locale’ hook.


Return Return

(string) The locale of the blog or from the 'locale' hook.


Top ↑

Source Source

File: wp-includes/l10n.php

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function get_locale() {
    global $locale, $wp_local_package;
 
    if ( isset( $locale ) ) {
        /**
         * Filters the locale ID of the WordPress installation.
         *
         * @since 1.5.0
         *
         * @param string $locale The locale ID.
         */
        return apply_filters( 'locale', $locale );
    }
 
    if ( isset( $wp_local_package ) ) {
        $locale = $wp_local_package;
    }
 
    // WPLANG was defined in wp-config.
    if ( defined( 'WPLANG' ) ) {
        $locale = WPLANG;
    }
 
    // If multisite, check options.
    if ( is_multisite() ) {
        // Don't check blog option when installing.
        if ( wp_installing() || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
            $ms_locale = get_site_option( 'WPLANG' );
        }
 
        if ( $ms_locale !== false ) {
            $locale = $ms_locale;
        }
    } else {
        $db_locale = get_option( 'WPLANG' );
        if ( $db_locale !== false ) {
            $locale = $db_locale;
        }
    }
 
    if ( empty( $locale ) ) {
        $locale = 'en_US';
    }
 
    /** This filter is documented in wp-includes/l10n.php */
    return apply_filters( 'locale', $locale );
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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