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: When the language selector is clicked, the format of the URL is incorrect.

Solution: Apparently, the user theme was not fully compatible with WPML. For this reason, the link to switch the language was being displayed incorrectly.

It was necessary to add a function to filter the URL and display it correctly.

Relevant Documentation: https://wpml.org/forums/topic/wpml-redirects-me-to-wrong-urls/#post-1189942 https://wpml.org/forums/topic/wpml-redirects-me-to-wrong-urls/#post-1191420

This topic contains 14 replies, has 4 voices.

Last updated by fellipeB 2 years, 8 months ago.

Assigned support staff: Bruno.

Author Posts
January 19, 2017 at 5:34 am #1185543

mohammadA-14

When ever, I try to go back to default language Which is english. It takes me to an other url which is not right. For example I am in Sahalaa.com ( English version ). When I click on Arabic Icon It takes me to the Arabic version of homepage which is hidden link. Now I want to back to the english version. When I click on English flag it takes me to wrong Url: hidden link.

Also, When I am in any other Arabic version page like Contact us: and I want to read the English version of Contact us. Whenever I click on English button. It reloads and takes me in the same place where I was. Again and again in the same Arabic Contact Us page.

Please help me via youtube video or Clear answer.

I am using Autotrader a themefuse product.

URL of (my) website where problem appears: sahalaa.com

January 19, 2017 at 12:49 pm #1185963

Bruno
Supporter

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

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

Thank you for contacting us.

I've seen both of the problems you're reporting.

Please as a test, could you disable all non-WPML plugins, switch to the default WordPress theme and see if the problem persists?

These steps are important so that we can know if this is a compatibility issue.

Thank you.

January 20, 2017 at 10:21 pm #1187458

mohammadA-14

Hi, I tried this. deactivated all plugins except WPML but still the same thing. Nothing happens.

January 23, 2017 at 12:38 pm #1188279

Bruno
Supporter

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

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

Hi,

Do you have changed your theme to default theme for too (e.g.: Twenty Seventeen)?

Also, I noticed that you are using 40MB of memory. The WPML requires at least 128MB: https://wpml.org/home/minimum-requirements/

Please, could you increase the memory limit for WordPress? To do it, please open the wp-config.php file in the root of your WordPress installation and after the opening PHP tag, add these lines:

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

E.g.:

<?php

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

After following the steps above, please let me know if the problem persists.

Thank you.

January 24, 2017 at 2:58 am #1188861

mohammadA-14

Hello,

When I changed my theme to Twenty seventeen The Language button is not visible also My website data was not visible correctly. (Check Screenshot)

I changed my limit to 256M. As you asked for.

Please can you do a video chat with me so, we can solve this issue more quietly. Also the owner of this site is asking me for update. and I am in big trouble with this error.

Hope to hear from you soon...!

Thanks
Aljasem

January 24, 2017 at 12:06 pm #1189266

Bruno
Supporter

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

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

Hello,

I'll contact 2nd tier about the video call.

Meanwhile, could I check your website? I need to request temporary access (wp-admin and FTP) to your site - preferably to a test site where the problem has been replicated if possible - in order to be of better help.

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

*** Note: Please make a full backup of your site.

Privacy and Security when Providing Debug Information for Support: https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Thank you.

January 24, 2017 at 11:07 pm #1189942

Bruno
Supporter

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

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

Thank you. This looks like a compatibility issue with your theme. The language selector link is incorrect and therefore the page is redirected incorrectly.

To fix the problem, I've added this custom function in the functions.php file of your theme:

add_filter( 'WPML_filter_link', 'wpml_fix_menu_link', 10, 2);
function wpml_fix_menu_link( $url, $data ) {

	if( is_home() || is_front_page() ) {
		global $sitepress;

		if( $data['code'] == $sitepress->get_default_language() ) {
			$url = get_site_url('', '/');
		} else {
			$url = add_query_arg( 'lang', $data['code'], get_site_url('', '/') );
		}
	}

	return $url;
}

This fixes the language selector issue when using the URL format as a parameter.

Please, could you check if your site is working as desired? If so, I'll forward this topic to our compatibility team.

Thank you.

January 25, 2017 at 10:35 pm #1190964

mohammadA-14

Hi,

The Homepage fixed Thanks but in other pages. for example when I am at Find a Car page. And I want to go to back to eng version. It just reload my page but I didn't get into English version page.

Can you also please fix this

Thanks in Advance.

January 26, 2017 at 12:09 pm #1191420

Bruno
Supporter

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

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

Hi,

I've added these five lines to fix the language selector problem for search pages. The change was made in the wp-content/themes/autotrader-parent/functions.php on line 27 - 31:

if( is_search() ) {
	if( $data['code'] == $sitepress->get_default_language() ) {
		$url = preg_replace( '/\&?lang=([a-z]+)/', '', $url );
	} 
}

Please, could you check if the site is working properly?

Thank you.

January 27, 2017 at 10:50 pm #1192791

mohammadA-14

Hi Bruno,

I appreciate your help but still there are 2 pages. where I am facing the similar problem. In Contact us Page ( Location ).

When I click on Arabic Language it takes me to the Arabic version of contact us. But When I try to come back to my original Default English language. After clicking on switcher. It takes me to the same page again and again.

The page Reloads and again takes me to the Arabic version. The two pages url is in the attachment.

hidden link

hidden link

January 30, 2017 at 2:43 pm #1193830

Bruno
Supporter

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

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

Hi,

I'll check those pages and soon I'll contact you.

Thank you.

January 30, 2017 at 3:50 pm #1193925

Bruno
Supporter

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

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

Hi,

I've fixed the two pages mentioned. Please, could you check if your website is working properly?

Thank you.

January 30, 2017 at 5:38 pm #1194068

mohammadA-14

Hi Bruno,

Thank you so much for your help. I really appreciate what you did for me. My issues are solved. Thanks.
Aljasem

September 6, 2018 at 9:04 pm #2712341

PureReturn

This didn't exactly help me but it led me to fixing my issue.
In my case WPML was resorting to using WP_HOME constant for getting the default language URL assuming this stays the same for all users.
In a domain per language setup we were changing the variable based on the current connected domain.
Having this fixed to our main default language domain fixed the issue but it would be better if WPML could have used the domains that are setup in WPML > Languages.

PS do not use

get_site_url();

instead use

get_home_url();

. If your like me and have WordPress installed in another directory

get_site_url();

will output you directory structure to WordPress install.

May 13, 2019 at 8:41 pm #3801513

fellipeB

Hello. I have a similar problem. When I switch the selector to another language (Portuguese, for example) I can not return to the English language. The theme used in WordPress is Curly. Can you help me?