is_locale_switched()WP 4.7.0

Whether switch_to_locale() is in effect.

1 time — 0.000019 sec (very fast) | 50000 times — 0.02 sec (speed of light) | PHP 7.0.14, WP 4.7

No Hooks.

Return

true|false. True if the locale has been switched, false otherwise.

Usage

is_locale_switched();

Examples

0

#1 Checking site language switching

Let's say our site runs in Russian (ru_RU) by default. But we switched the user's country by IP and switched the language to English (en_US). Now we need to tell the user that the language is switched. To do this, display a message, for example, in the header of the site (file header.php):

if( is_locale_switched() ){
	echo 'The site language is switched to '. get_locale();
}

Notes

  • Global. WP_Locale_Switcher. $wp_locale_switcher WordPress locale switcher object.

Changelog

Since 4.7.0 Introduced.

is_locale_switched() code WP 6.4.3

function is_locale_switched() {
	/* @var WP_Locale_Switcher $wp_locale_switcher */
	global $wp_locale_switcher;

	return $wp_locale_switcher->is_switched();
}