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 7 months ago.

Assigned support staff: Yvette.

Author Posts
March 18, 2019 at 2:26 pm #3370211

ricardoS-4

Hello.

We're hooking into wp and trying to parse the url and redirect it to another language based off a few conditions. This is the relevant part of code:

                $sitepress->switch_lang($languageis, true);
		do_action( 'wpml_switch_language', $languageis );
		$translated_url = apply_filters( 'wpml_permalink', get_current_full_url(), $languageis, true );

1. I was hoping the first two lines would do the trick but they do not.
2. While using wpml_permalink the issue is the following (imagining I am switching to 'en' and thus $languageis is 'en'):

hidden link
isn't correctly changed. It changes to:
hidden link

i.e. it keeps the de.

Using latest version of WPML. Thoughts?

Your help is very much appreciated ! Thanks.

March 19, 2019 at 12:29 am #3374095

Yvette
Supporter

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

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

Hello

I found an old ticket that seems to suggest you need to add the following before your code:
https://wpml.org/forums/topic/setting-current-language-programmatically/

global $sitepress;

So, to swtich the current active language it w be sufficient to do the following:

global $sitepress;
$sitepress->switch_lang($languageis, true);

The wpml_switch_language does not seem to be what you want as it only affects the related query...leaving the active language untouched. I would guess that this is why the permalink is still using the previous language in the URL.

Can you try this and let me know if it helps?

March 19, 2019 at 12:33 am #3374099

ricardoS-4

Nop. I have that added. This would throw a php error anyway ($sitepress is not defined ).

Problem here is both switch_lang and the other method aren't changing the url appropriately. Again notice my problem is very specific (it keeps /de).

Any other thoughts ?

I can provide access or.. ?

March 19, 2019 at 12:40 am #3374115

Yvette
Supporter

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

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

Are you using AJAX?

The topic ‘[Closed] wpml_permalink does not seem to be working’ is closed to new replies.