WPML issue: getting rid of Browser Language Redirect (UPDATED)

Home>IT resources>Web development>WordPress>WPML issue: getting rid of Browser Language Redirect (UPDATED)

WPML issue: getting rid of Browser Language Redirect (UPDATED)

Popular plugin WPML, which makes WordPress run in multilingual mode, in current (2.6.1) version has a bug – through JavaScript it redirects from homepage to secondary language.

In general, WPML’s JavaScript-based redirection can be controlled by setting “Browser language redirect” (icl_automatic_redirect), but even when setting it to “Disable browser language redirect” problem remains: when you open up repecka.net (primary content language is Lithuanian), you get redirected to repecka.net/en/, which is secondary site language (English). Then cookie (_icl_current_language) is set and next time in 24 hrs you will not get redirected. Still, this is an irritating bug and has been discussed already by several users in WPML forum.

Fix should be present in version 2.6.2, but until that as quick workaround I suggest disabling Browser Language Redirect from the code – edit inc/browser-redirect.php as follows (comment out like #9):

<?php
// adapted from http://wordpress.org/extend/plugins/black-studio-wpml-javascript-redirect/
// thanks to Blank Studio - http://www.blackstudio.it/

class WPML_Browser_Redirect{

    static function init(){
        if(!is_admin() && !isset($_GET['redirect_to']) && !preg_match('#wp-login\.php$#', preg_replace("@\?(.*)$@", '', $_SERVER['REQUEST_URI']))) {
                // add_action( 'wp_print_scripts', array('WPML_Browser_Redirect', 'scripts'));
        }
    }

At least on this site workaround works 🙄

Update

I’ve got development version from WPML team, installed and confirm that issue is solved. Therefore currently exist three problem solution options:

  1. Contact WPML support, get development version (it is still tagged as 2.6.1) and install it according to instructions team provides;
  2. Use my workaround (only in case you don’t use/need Browser Language Redirect option);
  3. Wait for WPML 2.6.2 with solution already implemented.
2016-10-24T10:56:36+00:00 2012-12-01|WordPress|0 Comments

About the Author:

Gytis Repečka is System analyst with passion to open source, electronics & cars, spreading bits about tech, music and privacy.

Leave A Comment