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 4 years, 9 months ago.

Assigned support staff: Bobby.

Author Posts
April 27, 2017 at 11:16 pm #1263876

John

I am using WPML to host content internationalized content with multiple versions in EN:

EN-us
EN-ca

This is what I am hoping to accomplish:

1. If someone from CA visits a US page (ie website.com/us/*), load that page but show a message/popup saying "Looks like you are trying to access our US site from Canada. Want to continue to the Canadian site? [clicking yes sends them to the equivalent page in the EN-ca language; clicking no hides the popup and sets a cookie to never show the popup again]

2. The inverse of the above.

I have seen this functionality on sites like google, microsoft etc. and must believe it is a popular request.

I have a GEOIp plugin and could code something like this in PHP/JS but I am wondering if anyone knows of a plugin that already accomplishes this out of the box? Like a piggy back plugin to WPML? Or sample code to save some time?

Thank you community!

PS I did some searching in the forums and couldn't find anything for this specific use case.

April 28, 2017 at 12:56 am #1263899

Bobby
Supporter

Languages: English (English )

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

Hi there,

WPML currently offers the ability to do an automatic broswer language redirect which essentially detects the visitors 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 its 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 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