WordPress at a glance
Home All Hooks Hooks

locale filter-hook . WP 1.5.0

Allows you to change the name of the locale (en_US), which WordPress gets in too many places around its code, via the function get_locale().


add_filter( 'locale', 'filter_function_name_9802' );
function filter_function_name_9802( $locale ){
	// filter...

	return $locale;
The locale ID. Example: en_US, ru_RU.


#1 Change the localization language

This example shows how to change the localization language in WordPress based on the language variable passed in $_GET query parameter:

add_filter( 'locale', 'set_my_locale' );
function set_my_locale( $lang ) {
	if( 'ru' == $_GET['language'] )
		return 'ru_RU';
		return $lang;

Where the hook is called

wp-includes/l10n.php 41
return apply_filters( 'locale', $locale );
wp-includes/l10n.php 75
return apply_filters( 'locale', $locale );

Where the hook is used (in WP core)

wp-includes/class-wp-locale-switcher.php 60
add_filter( 'locale', array( $this, 'filter_locale' ) );
No comments
    Hello, !     Log In . Register