WordPress at Your Fingertips

locale filter-hook . WP 1.5.0

Allows you to change the site locale (ex: en_US), which retrieved by the get_locale() function.

Usage

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

	return $locale;
}
$locale(string)
The locale ID. Example: en_US, ru_RU.

Examples

#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';
	else
		return $lang;
}

Changelog

Since 1.5.0 Introduced.

Where the hook is called

get_locale()
locale
wp-includes/l10n.php 80
return apply_filters( 'locale', $locale );
wp-includes/l10n.php 35
return apply_filters( 'locale', $locale );

Where in WP core the hook is used WordPress

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