Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is creating German and English profile pages using the WordPress API and the WPML language attribute. However, these pages are not connected in WordPress, resulting in the language switcher not being available on the pages. The client wishes to programmatically mark pages as translations of each other using the API.
Solution:
We recommend connecting the pages either using the following hook or manually:

If you are using the REST API, WPML does not provide a direct method for this. However, you can create a custom REST API endpoint that utilizes the

wpml_set_element_language_details

hook to set a page as a translation of another. If this is beyond your technical capabilities, you may consider hiring a developer:
https://wpml.org/contractors/

If this solution does not seem relevant to your situation, please open a new support ticket here: WPML support forum.

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 3 voices.

Last updated by Christopher Amirian 1 year, 5 months ago.

Assisted by: Christopher Amirian.

Author Posts
January 29, 2024 at 1:39 pm #15238537

zentralerE

We are creating german and english profile pages using the WordPress API and the wmpl language attribute. Our problem is now, that those german and english pages are not connected in WordPress, therefore the language switcher is not available on the pages.

Is there any way to programmatically (e.g. with the api) to mark to pages as translations of each other?

January 29, 2024 at 1:49 pm #15238607

Dražen
Supporter

Languages: English (English )

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

Hi,

Thank you for contacting WPML support. While you are waiting for one of my colleagues to take this ticket and work on it, let me provide you with the first debugging steps or if I can help with the issue quickly.

The best way would be to either connect them via the next hook or manually, please check the related docs:

- https://wpml.org/wpml-hook/wpml_set_element_language_details/
- https://wpml.org/faq/how-to-link-already-translated-pages/

Regards,
Drazen

January 29, 2024 at 3:19 pm #15239357

zentralerE

Hi,

thank you for the quick response.

The first link helps me to understand how to do it in wordpress, maybe in a plugin. But we are using the wordpress api to create the pages and it would be nice to also use the api to connect those pages.

January 30, 2024 at 8:40 am #15242004

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

If you mean the REST API, then WPML does not have any method there to help.

But you can create a custom REST API yourself where you can utilize the hook my colleague mentioned there as the PHP backend work:

https://wpml.org/wpml-hook/wpml_set_element_language_details/

The hook above is the only way that you can set a page to be a translation of another page. So if you use REST API, you need to create a custom one, that exposes the same Hook in question to that custom REST API for doing that.

If it is not what you can do, you can consider hiring a developer to do that for you:

https://wpml.org/contractors/

Thanks.

February 2, 2024 at 7:25 am #15257983

zentralerE

Hi,

thank you for the explanation. I think we have all necessary components and can implement it from here.

Best regards.