Skip Navigation

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

Last updated by Marcel 4 years, 7 months ago.

Assisted by: Marcel.

Author Posts
October 19, 2020 at 8:29 am #7255553

darceyD-2

I am trying to: have links pointing to right page (page in right language)

Link to a page where the issue can be seen: -

I expected to see: when browsing e.g. Spanish website, I expect links to point to Spanish pages.

Instead, I got: All links point to the default language (english)

After getting the id with the function icl_object_id() and getting the permalink it works again.

It stopped working just recently. I only updated Woocommerce and WPML

October 20, 2020 at 1:14 am #7261773

Marcos Vinicios Barreto

Hello,

Thank you for contacting our support service. The icl_object_id is deprecated in the most recent versions of WPML, please, change all the occurrencies to wpml_object_id and you should have it working properly again.

See: https://wpml.org/wpml-hook/wpml_object_id/

Please, let me know if it helps to solve your issue, have a nice day.

October 20, 2020 at 5:17 am #7262793

darceyD-2

I expect the get_permalink() function to return the url of the right page. The page of e.g. the Spanish translation, if I’m on a Spanish page. Right now, on the Spanish homepage, the get_permalink() function returns the urls of English pages. And not the (translated and available) urls of Spanish pages.

I was able to quick fix this with the deprecated function mentioned above. Thanks for noting the function is deprecated, but my question - in the first place - was about something else.

the url to th

October 20, 2020 at 6:32 pm #7269043

Marcos Vinicios Barreto

Hello,

Thank you for the updates. I am not sure if I understand your request into details, sorry for that, but it seems you want the core WordPress get_permalink() to return the url of the current page in the language it is being viewed, it won't work as the secondary language page/posts will have different IDs from the primary language, so, for that you need to pass the correct language ID and here is what the 'wpml_object_id' filter comes in.

Please, let me know if brings some more clarifications to your questions. Have a nice day.

October 20, 2020 at 7:37 pm #7269285

darceyD-2

It's not that complicated... I just want the get_permalink() core WP function to return the right url. When viewing the homepage in Spanish, I expect the get_permalink() function to return Spanish urls (so with query param ?lang=es). When viewing the homepage in German, I expect the get_permalink() function to return German urls (so with query param ?lang=de).

It has always worked like this. After my change described in the first comment it works again. But I expect the native WP function to return the right url (not the - default language- url without a language query param).

October 22, 2020 at 3:04 pm #7286233

Marcel
Supporter

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

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

Hi,

my name is Marcel and I will take over your case, as my colleague Marcos is not available today

But I expect the native WP function to return the right url (not the - default language- url without a language query param).

The Core function will not return the language as they have different IDs. The correct way to handle this is via our WPML API using the hook mentioned above "wpml_object_id". Please understand that we can't support a deprecated API where it seems it was working for you in the past.

Here you can find more information about this hook: https://wpml.org/wpml-hook/wpml_object_id/

Best Regards
Marcel