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 3 replies, has 2 voices.

Last updated by Yvette 4 months ago.

Assigned support staff: Yvette.

Author Posts
June 12, 2019 at 11:09 am #4003359

testalize.me

Hi there,

This issues has been dealt with before, we need some assistance.

Our website is translated into German. Now we would like a redirection based on IP. I know this is custom work and we can code ourselves or with some outside help. But I found this on the support forum:

$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;

}

Can this code be used in the functions.php? Or did I misinterpret it?

And we use it for NL and DE is this the code:

$get_country = New IPCountry();
$get_country_location = $get_country->resolve_IP('127.0.0.1');

if( $get_country_location == 'netherlands' ) {
wp_redirect( get_bloginfo('url') . "" );
exit;

}elseif( $get_country_location == 'germany' ) {
wp_redirect( get_bloginfo('url') . "/de/" );
exit;

}

So the Dutch version needs to be just our root. And for German visitors there needs to be a redirect. Could you help out pointing us in the right direction?

June 12, 2019 at 3:56 pm #4005905

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

Hello

I´m sorry to say but this is really outside the scope of our support policy and of my abilities to program.

I see you got this code snippet from here:
https://wpml.org/forums/topic/geolocation-3/#post-1263899

Please note that it is not "complete" and is only a suggested direction as the actual calls would depend on the plugin that you decide to use to determine the country. e.g. New IPCountry()

The answer already provided is really the best one that I could give you.

June 12, 2019 at 4:21 pm #4006097

testalize.me

Thank you.
Are you guys working on something like this? I think lots of users can use a feature like this since the browser redirect isn't really appreciated by Google.

We will contact our developers for now.

June 13, 2019 at 7:42 am #4010267

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

Please do make the feature request here:
https://wpml.org/suggest-a-new-feature-for-wpml/

If/when there are enough clients asking for the same feature, I know the possibility is seriously evaluated.

Thanks