• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / get_locale() – Retrieves the current locale.

You appear to be a bot. Output may be restricted

Description

Retrieves 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.

Usage

$string = get_locale();

Parameters

Returns

string The locale of the blog or from the locale hook.

Source

File name: wordpress/wp-includes/l10n.php
Lines:

1 to 52 of 52
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 );
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 2nd April 2020

Primary Sidebar

Information

Function name: get_locale
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/l10n.php
File ref: wp-includes/l10n.php
Deprecated?: No
API Letters: G,L

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites