Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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

Last updated by Daniel 6 years, 5 months ago.

Assigned support staff: Bruno.

Author Posts
June 18, 2013 at 3:24 pm #136923

Daniel

Hi there, I am trying to introduce language redirection by accessing geolocation.
I am using ip2location for this and get the country code in the end, which works fine.
Then I check, if the current site language corresponds to the users country and redirect, if not with following code:

global $sitepress;
if($sitepress->get_current_language() != $country_language_code){
  $languages = $sitepress->get_ls_languages();
var_dump($languages);
  if(isset($languages[$country_language_code])){
    wp_safe_redirect($languages[$country_language_code]['url'], 301);
    exit;
  } else{
	
    wp_safe_redirect(home_url(), 301);
	exit;

	}
}

When I now try to alter the language_code in the url lets say from en to de, wordpress goes into a infinite loop because it tries to fetch an url in the format of domain.com/de/en/

I hook my redirect function into add_action( 'template_redirect', 'wpml_geo_location_redirect');

How can I make wordpress to still look for domain.com/de/some_post and then check with the users geolocation if he is allowed to access that page and if not redirect him back to domain.com/en/ ?

June 18, 2013 at 3:49 pm #136932

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Dear Daniel,

Please, replace this line:

wp_safe_redirect(home_url(), 301);

by this:

wp_safe_redirect(site_url(), 301);

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Thank you.

June 18, 2013 at 4:57 pm #136949

Daniel

Thanks for your quick reply. Unfortunately, that does not prevent wordpress from going into a loop and producing a /lang/lang url, when manually changing the lang parameter in the url...

June 18, 2013 at 7:17 pm #136975

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Dear Daniel,

Please, try this one:

wp_safe_redirect(site_url('/'), 301);

Please let me know if this solves the problem.

June 18, 2013 at 8:59 pm #136998

Daniel

Hi Bruno
I ended up using the geo redirect plugin (http://wordpress.org/plugins/geographical-redirect/) and i got it to work.
thanks for your assistance.