get_locale

The timeline below displays how wordpress function get_locale has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.7

/**
 * Core Translation API
 *
 * @package WordPress
 * @subpackage i18n
 * @since 1.2.0
 */
/**
 * Retrieves the current locale.
 *
 * If the locale is set, then it will filter the locale in the {@see '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 {@see '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 {@see 'locale'} hook.
 *
 * @since 1.5.0
 *
 * @global string $locale           The current locale.
 * @global string $wp_local_package Locale code of the package.
 *
 * @return string The locale of the blog or from the {@see 'locale'} hook.
 */
function get_locale()
{
    global $locale, $wp_local_package;
    if (isset($locale)) {
        /** This filter is documented in wp-includes/l10n.php */
        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()) {
            $ms_locale = get_site_option('WPLANG');
        } else {
            $ms_locale = get_option('WPLANG');
            if (false === $ms_locale) {
                $ms_locale = get_site_option('WPLANG');
            }
        }
        if (false !== $ms_locale) {
            $locale = $ms_locale;
        }
    } else {
        $db_locale = get_option('WPLANG');
        if (false !== $db_locale) {
            $locale = $db_locale;
        }
    }
    if (empty($locale)) {
        $locale = 'en_US';
    }
    /**
     * Filters the locale ID of the WordPress installation.
     *
     * @since 1.5.0
     *
     * @param string $locale The locale ID.
     */
    return apply_filters('locale', $locale);
}

WordPress Version: 5.4

/**
 * Core Translation API
 *
 * @package WordPress
 * @subpackage i18n
 * @since 1.2.0
 */
/**
 * Retrieves the current locale.
 *
 * If the locale is set, then it will filter the locale in the {@see '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 {@see '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 {@see 'locale'} hook.
 *
 * @since 1.5.0
 *
 * @global string $locale           The current locale.
 * @global string $wp_local_package Locale code of the package.
 *
 * @return string The locale of the blog or from the {@see 'locale'} hook.
 */
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()) {
            $ms_locale = get_site_option('WPLANG');
        } else {
            $ms_locale = get_option('WPLANG');
            if (false === $ms_locale) {
                $ms_locale = get_site_option('WPLANG');
            }
        }
        if (false !== $ms_locale) {
            $locale = $ms_locale;
        }
    } else {
        $db_locale = get_option('WPLANG');
        if (false !== $db_locale) {
            $locale = $db_locale;
        }
    }
    if (empty($locale)) {
        $locale = 'en_US';
    }
    /** This filter is documented in wp-includes/l10n.php */
    return apply_filters('locale', $locale);
}

WordPress Version: 5.3

/**
 * Core Translation API
 *
 * @package WordPress
 * @subpackage i18n
 * @since 1.2.0
 */
/**
 * Retrieves the current locale.
 *
 * If the locale is set, then it will filter the locale in the {@see '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 {@see '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 {@see 'locale'} hook.
 *
 * @since 1.5.0
 *
 * @global string $locale
 * @global string $wp_local_package
 *
 * @return string The locale of the blog or from the {@see 'locale'} hook.
 */
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()) {
            $ms_locale = get_site_option('WPLANG');
        } else {
            $ms_locale = get_option('WPLANG');
            if (false === $ms_locale) {
                $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);
}

WordPress Version: 4.9

/**
 * Core Translation API
 *
 * @package WordPress
 * @subpackage i18n
 * @since 1.2.0
 */
/**
 * Retrieves the current locale.
 *
 * If the locale is set, then it will filter the locale in the {@see '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 {@see '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 {@see 'locale'} hook.
 *
 * @since 1.5.0
 *
 * @global string $locale
 * @global string $wp_local_package
 *
 * @return string The locale of the blog or from the {@see 'locale'} hook.
 */
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);
}

WordPress Version: 4.6

/**
 * Core Translation API
 *
 * @package WordPress
 * @subpackage i18n
 * @since 1.2.0
 */
/**
 * Retrieves the current locale.
 *
 * If the locale is set, then it will filter the locale in the {@see '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 {@see '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 {@see 'locale'} hook.
 *
 * @since 1.5.0
 *
 * @global string $locale
 * @global string $wp_local_package
 *
 * @return string The locale of the blog or from the {@see 'locale'} hook.
 */
function get_locale()
{
    global $locale, $wp_local_package;
    if (isset($locale)) {
        /**
         * Filters WordPress install's locale ID.
         *
         * @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);
}

WordPress Version: 4.4

/**
 * Core Translation API
 *
 * @package WordPress
 * @subpackage i18n
 * @since 1.2.0
 */
/**
 * Retrieves the current locale.
 *
 * If the locale is set, then it will filter the locale in the {@see '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 {@see '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 {@see 'locale'} hook.
 *
 * @since 1.5.0
 *
 * @global string $locale
 * @global string $wp_local_package
 *
 * @return string The locale of the blog or from the {@see 'locale'} hook.
 */
function get_locale()
{
    global $locale, $wp_local_package;
    if (isset($locale)) {
        /**
         * Filter WordPress install's locale ID.
         *
         * @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);
}

WordPress Version: 4.3

/**
 * WordPress Translation API
 *
 * @package WordPress
 * @subpackage i18n
 */
/**
 * Get the current locale.
 *
 * 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.
 *
 * @since 1.5.0
 *
 * @global string $locale
 * @global string $wp_local_package
 *
 * @return string The locale of the blog or from the 'locale' hook.
 */
function get_locale()
{
    global $locale, $wp_local_package;
    if (isset($locale)) {
        /**
         * Filter WordPress install's locale ID.
         *
         * @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 (defined('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);
}

WordPress Version: 4.0

/**
 * WordPress Translation API
 *
 * @package WordPress
 * @subpackage i18n
 */
/**
 * Get the current locale.
 *
 * 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.
 *
 * @since 1.5.0
 *
 * @return string The locale of the blog or from the 'locale' hook.
 */
function get_locale()
{
    global $locale, $wp_local_package;
    if (isset($locale)) {
        /**
         * Filter WordPress install's locale ID.
         *
         * @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 (defined('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);
}

WordPress Version: 3.9

/**
 * WordPress Translation API
 *
 * @package WordPress
 * @subpackage i18n
 */
/**
 * Get the current locale.
 *
 * 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.
 *
 * @since 1.5.0
 *
 * @return string The locale of the blog or from the 'locale' hook.
 */
function get_locale()
{
    global $locale;
    if (isset($locale)) {
        /**
         * Filter WordPress install's locale ID.
         *
         * @since 1.5.0
         *
         * @param string $locale The locale ID.
         */
        return apply_filters('locale', $locale);
    }
    // WPLANG is defined in wp-config.
    if (defined('WPLANG')) {
        $locale = WPLANG;
    }
    // If multisite, check options.
    if (is_multisite()) {
        // Don't check blog option when installing.
        if (defined('WP_INSTALLING') || false === $ms_locale = get_option('WPLANG')) {
            $ms_locale = get_site_option('WPLANG');
        }
        if ($ms_locale !== false) {
            $locale = $ms_locale;
        }
    }
    if (empty($locale)) {
        $locale = 'en_US';
    }
    /** This filter is documented in wp-includes/l10n.php */
    return apply_filters('locale', $locale);
}

WordPress Version: 3.8

/**
 * WordPress Translation API
 *
 * @package WordPress
 * @subpackage i18n
 */
/**
 * Get the current locale.
 *
 * 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.
 *
 * @since 1.5.0
 *
 * @return string The locale of the blog or from the 'locale' hook.
 */
function get_locale()
{
    global $locale;
    if (isset($locale)) {
        /**
         * Filter WordPress install's locale ID.
         *
         * @since 1.5.0
         *
         * @param string $locale The locale ID.
         */
        return apply_filters('locale', $locale);
    }
    // WPLANG is defined in wp-config.
    if (defined('WPLANG')) {
        $locale = WPLANG;
    }
    // If multisite, check options.
    if (is_multisite()) {
        // Don't check blog option when installing.
        if (defined('WP_INSTALLING') || false === $ms_locale = get_option('WPLANG')) {
            $ms_locale = get_site_option('WPLANG');
        }
        if ($ms_locale !== false) {
            $locale = $ms_locale;
        }
    }
    if (empty($locale)) {
        $locale = 'en_US';
    }
    // duplicate_hook
    return apply_filters('locale', $locale);
}

WordPress Version: 3.7

/**
 * WordPress Translation API
 *
 * @package WordPress
 * @subpackage i18n
 */
/**
 * Get the current locale.
 *
 * 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.
 *
 * @since 1.5.0
 *
 * @return string The locale of the blog or from the 'locale' hook.
 */
function get_locale()
{
    global $locale;
    if (isset($locale)) {
        /**
         * Filter WordPress install's locale ID.
         *
         * @since 1.5.2
         *
         * @param string $locale The locale ID.
         */
        return apply_filters('locale', $locale);
    }
    // WPLANG is defined in wp-config.
    if (defined('WPLANG')) {
        $locale = WPLANG;
    }
    // If multisite, check options.
    if (is_multisite()) {
        // Don't check blog option when installing.
        if (defined('WP_INSTALLING') || false === $ms_locale = get_option('WPLANG')) {
            $ms_locale = get_site_option('WPLANG');
        }
        if ($ms_locale !== false) {
            $locale = $ms_locale;
        }
    }
    if (empty($locale)) {
        $locale = 'en_US';
    }
    // duplicate_hook
    return apply_filters('locale', $locale);
}