switch_to_locale() WordPress Function

The switch_to_locale() function is used to change the active WordPress locale. This is useful for site owners who want to create a multilingual WordPress site. The function takes a locale code as an argument, and the locale code must be supported by WordPress. The switch_to_locale() function is located in wp-includes/locale.php.

switch_to_locale( string $locale ) #

Switches the translations according to the given locale.


Parameters

$locale

(string)(Required)The locale.


Top ↑

Return

(bool) True on success, false on failure.


Top ↑

Source

File: wp-includes/l10n.php

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

	return $wp_locale_switcher->switch_to_locale( $locale );
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.