In this previous questions, someone told me how to make WPLANG clickleable, so that the user can choose his preferred language (usually you can only define WPLANG by modifying the wp-config). But I’m sure how to make the link. Are the following functions giving me the possibility of using example/?lang=
Or example/en
?
*wp-lang.php
session_start();
if ( isset( $_GET['lang'] ) ) {
$_SESSION['WPLANG'] = $_GET['lang'];
define ('WPLANG', $_SESSION[WPLANG]);
} else {
if(isset($_SESSION['WPLANG'])) {
define ('WPLANG', $_SESSION['WPLANG']);
$_GET['lang'] = $_SESSION['WPLANG'];
} else {
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ) {
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
$languages = explode( ",", $languages );
$_SESSION['WPLANG'] = $languages[0];
$_SESSION['WPLANG'] = str_replace("-", "_", $_SESSION['WPLANG']);
$_GET['lang'] = substr($_SESSION['WPLANG'],0,2);
define ('WPLANG', $_SESSION[WPLANG]);
} else {
define ('WPLANG', '');
}
}
}
*wp-config.php – Find the section where the constant WPLANG is defined. Add in the following line just before the WPLANG declaration.
require_once(dirname(__FILE__).'/wp-lang.php');
define ('WPLANG', '');
I was modifying
WP_LANG
conditionally directly in wp-config.php using$_GET['lang']
andhttp://example.com/wp-admin/lang=es_ES
.In this example (used in
wp-config.php
), I’ve added a cookie, so once you go to any admin link?lang=lang_COUNTRY
, the subsequent loads will be on the new language.