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.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Rohan Sadanandan 1 month, 2 weeks ago.

Assigned support staff: Rohan Sadanandan.

Author Posts
September 4, 2019 at 4:22 pm #4512853

joA

Hello, i'm using this function:

add_filter('get_the_permalink','my_permalink_redirect');
function my_permalink_redirect($permalink) {
global $post;
if ($post->ID == 6342) {
$permalink = '/en/about-us/vision/';
}
return $permalink;
}

That should redirect when page is opened to another page, but i have two languages: English and Slovenian. When i try to go to english and open this page, it redirects to slovean page not the english one.

What could be the issue here?

September 4, 2019 at 5:36 pm #4513225

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for contacting WPML Support.

From what I understand, if the current postID is 6342, you are redirecting to the English page. Please note that the postID is different for a page & the translation of that page.
So when you change the language the postID is not matched & hence it will not be redirected to the given link.

You can have look at this documentation for all the hooks available in WPML:
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

If you want to get the current language code, you can use this hook:
https://wpml.org/wpml-hook/wpml_current_language/

Thanks,
Rohan

September 5, 2019 at 3:36 pm #4520589

joA

Hi Rohan,

No, That is page that is alredy translated to english, its an page that is only for SEO, it's empty, and if you try to access it it should redirect to page that has this page as parent. So the url will look like /services/service1. I hope you understand me.

Kind regards

September 6, 2019 at 9:08 am #4524237

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

I don't get the exact issue.

This is what I understood from your code:
1. if the postID == 6342, then you set the $permalink value to "/en/about-us/vision/"
2. when you switch language, it's not working

While switching language, please try to print the value of the postID & make sure that the value is 6342.

If this is not what you are asking, could you please explain this in a more detailed/step by step way so that I can understand better.

Thanks,
Rohan