This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This thread is resolved. Here is a description of the problem and solution.

Problem: Site not redirecting based on browser language Solution: - Translations need to exist for pages in order to redirect - no JavaScript errors should exist on the site Relevant Documentation: https://wpml.org/documentation/getting-started-guide/language-setup/automatic-redirect-based-on-browser-language/

This topic contains 11 replies, has 3 voices.

Last updated by dennysP 10 months, 1 week ago.

Assigned support staff: Bruno Kos.

Author Posts
December 5, 2018 at 5:30 pm #2971131

rezaM-6

I am trying to: redirect the page based on Browser language.

Link to a page where the issue can be seen: hidden link

I expected to see: I have changed my Browser lang to Arabic but it still not redirecting to Arabic page.

Instead, I got:

December 6, 2018 at 8:35 am #2972955

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Thank you for contacting WPML support!

I’ve checked the site and indeed it does not redirect due to following error (visible in the error log):

 TypeError: jQuery.cookie is not a function - language-cookie.js

Can I ask you the following:

- Are you using caching mechanism on your site, such as CDN? Have you tried clearing the cache in full and trying again? (make sure to clear the browser cache before trying this each time)
- Can you switch temporarily to another theme (but first making the full backup of the site), such as Twenty Seventeen, clearing the cache and then trying again? The reason I am asking is because in the error log, I see “hidden link being called also so we may have a possible duplicate jquery conflict here, causing the redirection issue.

Very often there’s no need to load jQuery directly through theme since many plugins will request jQuery to load and WordPress will handle this part by default. Calling another jQuery manually through theme can cause conflicts and issues like this one.

Regards,
Bruno Kos

December 6, 2018 at 12:10 pm #2973681

rezaM-6

I have resolved the Site's error but still language is not redirecting.

Yes, we are using CDN Cloudflare and have cleared all the cache's and checked it. Not working

December 6, 2018 at 2:31 pm #2974460

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Now that I can see debug info, can we try some things first:
Update WPML plugin(s) to the latest versions (4.0.8. on your site at the moment)
Increase WP Memory limit to at least 256 MB? You can do this by adding this into wp-config.php file:

define( 'WP_MEMORY_LIMIT', '256M' );

You can find out more about this here:
https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP

Also, related to this issue, I still see jQuery being loaded through the theme, can you see to resolve this after you update plugins and memory limit, clear both browser and site cache and try again? The file that loads is this one:
wp-content/themes/neuroneum/scripts/jquery-1.12.4.js

You can check if the jquery issue is resolved using e.g. Google Chrome console:
hidden link

Regards,
Bruno Kos

December 6, 2018 at 2:40 pm #2974519

rezaM-6

Have updated the plugin and increased the memory limit.

There is not Jquery error found in Console.

Still not working redirection.

December 6, 2018 at 3:20 pm #2974715

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Please see attached image - based on this, the error is also still present. Can you recheck this once again?

Also, have you tried disabling all the plugins apart from WPML and trying with another theme such as Twenty Seventeen to test if the issue still persists?

Regards,
Bruno Kos

December 6, 2018 at 3:28 pm #2974750

rezaM-6

I have made a clone hidden link and actiate other theme and deactivated all the plugin except WPML

again not working

December 6, 2018 at 3:48 pm #2974813

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Could you provide me with temporary wp-admin administrator access for the backup site, so I could have a look inside? I have marked your reply as private so only WPML supporters and you will see these.

https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Regards,
Bruno Kos

December 7, 2018 at 1:40 pm #2978051

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Try opening this site now: hidden link, using any browser where Arabic is set as a main language and with cleared cookies (or you can open it in Private mode on Firefox or Incognito mode in Chrome). On your main site, based on my observations on the backup site, there are at least three reasons why redirection isn’t working:

- There was only one translation available (Chinese) and with that one, it worked without issues even before I made any changes
- In the “Browser language redirect” setting, there’s a “Redirect visitors based on browser language only if translations exist” setting chosen, which means that based on one existing translation, redirection will work only for Chinese at the moment
- There are still the same jQuery errors inside console, so until all these and other JavaScript are fixed, WPML redirection may not work since it it based on JavaScript itself

So next steps would be creating translations that don’t exist now (I suggest using Translation Management) and that you fix all Javascript issues on the site.
https://wpml.org/documentation/translating-your-contents/

Once you get all the above resolved and if redirection still isn’t working, let us know so we could investigate the issue further.

Regards,
Bruno Kos

December 11, 2018 at 4:55 pm #2989726

rezaM-6

hidden link

user: test
Pw: Sozep40QBJ(@DWzQu4j)^XDK

I have removed all the errors but still not redirecting .. I have added all the missing languages as well.

December 11, 2018 at 5:11 pm #2989770

rezaM-6

My issue is resolved now. Thank you!

July 5, 2019 at 2:51 pm #4152251

dennysP

Hello, I have this website

hidden link

and languages are IT/EN but we have also 1 single page in Chinese (+ Japanese)

hidden link
hidden link

We want that when user click on one of these languages it goes to that sigle page,

we tried with:

add_filter( 'WPML_filter_link', 'wp_redirect_another', 10, 2 );
function wp_redirect_another( $url, $lang ) {

$languages = icl_get_languages('skip_missing=1');

$lang = $lang['language_code'];
if( ! isset( $languages[ $lang ] ) ) {

//e.g. if jap
if( $lang == 'ja' ) { //change the language code
return '/japan/’;
}

//e.g. if chinese
if( $lang == 'zh-hang’ ) { //change the language code
return '/chinese’;
}

}

return $url;
}

But seems not working… thanks for any help