Skip to content Skip to sidebar

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.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 13:00 9:00 – 13:00 9:00 – 13:00 8:00 – 12:00 8:00 – 12:00 -
- 14:00 – 17:00 14:00 – 18:00 14:00 – 18:00 13:00 – 17:00 13:00 – 17:00 -

Supporter timezone: Europe/Zagreb (GMT+02:00)

This topic contains 5 replies, has 0 voices.

Last updated by Bruno Kos 8 months, 2 weeks ago.

Assisted by: Bruno Kos.

Author Posts
November 4, 2024 at 9:12 am #16359382

sebastianF-2

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?

November 4, 2024 at 12:01 pm #16360756

sebastianF-2

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.

November 5, 2024 at 7:48 am #16364386

sebastianF-2

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.

backend_english_same_language_link.png
November 6, 2024 at 2:25 pm #16372553

Bruno Kos
WPML Supporter since 12/2018

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.

November 8, 2024 at 8:26 am #16380897

sebastianF-2

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.

November 8, 2024 at 12:12 pm #16381909

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

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

I re-read the chat session again to see if I missing something, given that it was done with another supporter.

There you said that what our chat summary created (AI-powered) may not be entirely correct with its description.

If you can see my original ticket text, there is much more information than in this weird chat

Because check this:
hidden link

On this page I created URL that points to hidden link which is a translation.

And the URL stays as it is. Blacklist is only required if Sticky Links is used and according to your debug information, you are not using it.

Can you show me an example on the above sandbox, just to make sure we are on the same page?

I can then check with our 2nd tier for possible implementations.

November 11, 2024 at 7:58 am #16386985

sebastianF-2

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.

November 11, 2024 at 9:45 am #16387634

Bruno Kos
WPML Supporter since 12/2018

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.