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
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.
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.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.