Created
February 27, 2018 11:10
-
-
Save alexminza/03b78fd9e846d91d058e5db60be8921c to your computer and use it in GitHub Desktop.
WordPress locale language switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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