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.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Rudi 1 year, 11 months ago.

Assisted by: Shekhar Bhandari.

Author Posts
July 3, 2023 at 3:02 pm #13934487

Rudi

Hi there,

I am using a cloudflare worker to redirect visitors to their appropriate translated page based off of the cloudflare geolocation. It's working working well for the most part, except for when a wpml translation doesn't exist for the page in the visitors language. Is there a way to check if a translation exists before redirecting?

I've tried using await fetch("The requested page", { method: 'HEAD' }) with slight success, however, It always seems to return a 200, even if there is no translation available. eg. if this is a published page with no translations: hidden link, then fetching hidden link seems to return a 200 as well.

Do you have any suggestions/ideas?
Thanks in advance

July 4, 2023 at 6:50 am #13937345

Shekhar Bhandari
WPML Supporter since 03/2015

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello @rudir,

Welcome to WPML support. I'm here to assist you.

It appears that the redirection you mentioned is a result of the default WordPress redirections when a slug is matched. You can disable this behavior by following the instructions provided in this documentation: hidden link.

Additionally, you can utilize hooks to determine if a translation is available for a post. The following hooks can be used for this purpose:
- https://wpml.org/wpml-hook/wpml_element_trid/
- https://wpml.org/wpml-hook/wpml_get_element_translations/

When a page or post is created in WPML, the post details are stored in the `icl_translations` table with a `trid` ID. Any posts with the same `trid` represent translations of each other. To retrieve the translations, you will need to obtain the page/post ID, retrieve the `trid`, and then fetch the corresponding translations.
https://wpml.org/documentation/support/wpml-tables/

You can also utilize the REST API to retrieve these details, but you will need to expand the endpoint to include the translation details using the aforementioned hooks.

Please note that while I can provide guidance and assistance with examples, troubleshooting, and customization of code implementations, further customization or troubleshooting of custom code falls outside the scope of our support.

If the above solution does not resolve the issue or meet your specific requirements, it may be necessary to seek the assistance of a custom contractor or developer who can offer tailored solutions to your needs. You can find a list of contractors https://wpml.org/contractors/.

I'm looking forward to your response.

Thank you.