Skip Navigation

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 topic contains 1 reply, has 2 voices.

Last updated by Bobby 10 months, 3 weeks ago.

Assigned support staff: Bobby.

Author Posts
October 28, 2019 at 11:41 pm #4843335

tonyD-4

Hi,

How can I load a different versions of the site according to their location? As an example English as the default language for users from New Zeland where Malay as the default for users from Singapore?

October 29, 2019 at 12:34 am #4843377

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

WPML currently offers the ability to do an automatic browser language redirect which essentially detects the visitor's browser language and then if that language exists in your site it redirects them to it.

ex. Browser is set to Italian, and you have a site with Italian/English, once I visit I will be redirected to Italian.
The downfall with this is that it's based on the visitor's browser language rather than their location.

At the moment Geolocation is possible with custom coding which does fall beyond the scope of our support but perhaps I can point you in the right direction.

1. Use a plugin or PHP script to look up the IP and match it to a country. I don't have any specific recommendations but this is what I found:

IP2Location Redirection
https://wordpress.org/plugins/ip2location-redirection/

Geolify
https://wordpress.org/plugins/geolify/

IP2Location (PHP Class)
hidden link
hidden link
hidden link

2. Use wp_redirect to redirect the user:
https://codex.wordpress.org/Function_Reference/wp_redirect

Altogether it would look something like this:

$get_country = New IPCountry();
$get_country_location = $get_country->resolve_IP('127.0.0.1');
 
if( $get_country_location == 'usa' ) {
    wp_redirect( get_bloginfo('url') . "/en/" );
    //wp_redirect( get_bloginfo('url') . "?lang=en" );
    exit;
 
}elseif( $get_country_location == 'canada' ) {
    wp_redirect( get_bloginfo('url') . "/fr/" ); 
    //wp_redirect( get_bloginfo('url') . "?lang=fr" );
    exit;
 
}

I hope this helps.

3. You can also consider contacting one of our certified partners from this link:
http://wpml.org/documentation/support/wpml-contractors/

Before doing so please review this page:
http://wpml.org/documentation/support/wpml-contractors/guidelines-for-people-looking-for-consulting-help/

Kind Regards,
Bobby

The topic ‘[Closed] Country based redirect’ is closed to new replies.