Skip to content

Instantly share code, notes, and snippets.

@alexminza
Created February 27, 2018 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexminza/03b78fd9e846d91d058e5db60be8921c to your computer and use it in GitHub Desktop.
Save alexminza/03b78fd9e846d91d058e5db60be8921c to your computer and use it in GitHub Desktop.
WordPress locale language switch
<?php
function set_locale($lang) {
define('LANG_PARAM', 'lang');
$req_lang = $lang;
if(!isset($_SESSION))
session_start();
if(isset($_REQUEST[LANG_PARAM])) {
$req_lang = $_REQUEST[LANG_PARAM];
//remember language in user session
$_SESSION[LANG_PARAM] = $req_lang;
} else {
if(isset($_SESSION[LANG_PARAM]))
$req_lang = $_SESSION[LANG_PARAM];
}
return $req_lang;
}
add_filter('locale', 'set_locale');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment