Background of the issue:
I am trying to link from the English page hidden link to the German version of the same page at hidden link. The English page is set as a translation of the German version. This issue also occurs on other pages like hidden link and hidden link.
Symptoms:
In the frontend, the anchor-tag is rewritten or filtered to point to the English translation of the linked post instead of the specified German version, which is the page I currently have opened and want to link away from.
Questions:
Why is the link being rewritten to point to the English version instead of the German version?
How can I ensure that the link points to the correct German version in the frontend?
The proposed procedure mentioned in support chat does not resolve the issue.
As I already stated, I don't think it is in any way useful that custom code is required for every single page/link that should not be translated in the way it currently is.
If there is a generic code solution that instantly works for all links from and to all posts, I will be happy to implement it in my page.
If a user links to a post in another language inside the post content, the link should not be rewritten without the normal editor being able to disable this behavior for his link.
If this automatic preference of WPML to rewrite links to the current language is required for other features or client use cases, this might be understandable. But please, at least give users an option to disable this rewriting of links.
Related, but maybe slightly different "Bug"(?) that I just discovered:
On page hidden link I link to an English post hidden link of the custom post type "people". In the frontend, this link gets rewritten to hidden link, where "personen" is the German translated slug of the custom post type.
As the post with German post-type-slug "personen" does not exist in the English version of the whole site in the directory "/en", this link leads to a 404 page.
The same rewrite happens for all 7 persons being linked on this page.
This rewrite happens despite the user currently being on an English page, and the link points to an English post as well.
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+02:00)
What if you try something like this?
function wpml_disable_all_link_translation($blacklist, $sitepress) {
// Get all public post types
$args = [
'public' => true,
];
$post_types = get_post_types($args);
// Query all published posts/pages
$query_args = [
'post_type' => $post_types,
'post_status' => 'publish',
'fields' => 'post_name', // We only need slugs
'nopaging' => true,
];
$all_posts = get_posts($query_args);
// Add all post slugs to the blacklist
foreach ($all_posts as $post_slug) {
$blacklist[] = $post_slug;
}
return $blacklist;
}
add_filter('wpml_sl_blacklist_requests', 'wpml_disable_all_link_translation', 10, 2);
I haven't tested this, but note that on sites with a large number of posts, this might impact performance due to the size of the blacklist.
That code does not work. It just adds every (relevant) existing post slug to this $blacklist array, but that in general is a solution I already described as not working. It was a proposed solution in live chat already.
Apparantely the issue with the auto-rewritten URLs is not reproducible in this environment, so maybe this issue arises from the interaction with numerous other plugins. The link you created on hidden link pointing to hidden link would directly trigger the issue on my site, pointing to hidden link instead.
Unfortunately, condensing my own site environment down to a (possible) minimal setup, eradicating some or most other plugins (in a staging environment) would be quite complex due to the multiple dependencies the plugins build on each other. I can maybe try some things if you have concrete ideas.
---
> If you can see my original ticket text, there is much more information than in this weird chat
This comment of mine specifically referenced the first idea of Noman to try relative links instead of absolute links - which I already mentioned as "tried" in my original support request. But this original support request was apparantely deleted in favor of an AI-powered summary.
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+02:00)
I noticed that your site is using Elementor.
To investigate further, I’ve added it to a sandbox environment since it uses link rewriting. It seems to be functioning as expected here: [Privacy Policy - Sandbox](hidden link).
The issue on your site could stem from a variety of causes, and the only way to pinpoint it is through detailed debugging. Here’s what I suggest:
1. Create a simple test page with just a title and some text. Then, set up the linking the same way it’s done in my sandbox environment.
2. Provide me with WordPress credentials for your staging site so I can investigate further. You can follow these instructions for securely sharing your site’s copy: [How to Provide Supporters with a Copy of Your Site](https://wpml.org/faq/provide-supporters-copy-site/). For this I will install Duplicator Pro into your staging site.
3. Once I have access, I’ll escalate the case to our 2nd tier support team for in-depth debugging.
Let me know if this approach works for you!
The topic ‘[Closed] Link to same page in other language (translation) gets rewritten to link to current language (curren…’ is closed to new replies.