Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a Multilingual Wordpress functions to detect a language by pretty URLs like.. `` `` `` Add this code in your `functions.php` After added code go to `wp-admin/options-permalink.php` press `Save Changes` So you can use `<?php echo lang();?>` `<?php if( lang() === "en" ) ?>` In yo…
function lang_support() {
return array('en','fr'); // Add your support lang-code (1st place is a default)
function rewrite_lang(){
$langs = lang_support();
foreach($langs as $lang) {
function lang(){
global $wp_query;
$langs = lang_support();
$lang_r = "";
foreach($langs as $lang) {
if(isset($wp_query->query_vars[$lang])) {
$lang_r = $lang;
$_SESSION['lang'] = $lang_r;
if(in_array($lang_r,$langs)) {
return $lang_r;
} else {
return $langs[0];
function init_session(){session_start();}
function lang_session() { // Redirect by JS if session is set
$url_lang= basename($_SERVER['REQUEST_URI']);
if(!in_array($url_lang,lang_support()) && isset($_SESSION['lang'])) {
if(!is_404()) {
function output_buffer() {ob_start();}
function currentURL() {
return $pageURL;

This comment has been minimized.

Copy link

leecollings commented Oct 25, 2015

Hey, I'm trying to use this, and it works great.. although there seems to be one slight but major issue.

When trying to view the homepage, it will redirect to /localhost/en (for example).. and as a result will not show my static homepage (but instead shows the latest posts). I'm not using a blog on this site. Is there something that can be added to deal with static Front pages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.