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.

This topic contains 11 replies, has 2 voices.

Last updated by Nigel 1 year, 9 months ago.

Assisted by: Nigel.

Author Posts
July 11, 2022 at 12:24 am #11638013

takahiroK-2

I am trying to: Links are not translated in secondary language. I have contacted WPML support before about this issue

Link to a page where the issue can be seen:
hidden link

I expected to see:
Links being translated in secondary language

Instead, I got:
Seems like links do not get translated after there is a custom post type under custom post type.

As mentioned above we have contacted WPML support and were told to try out deactivating other plugin except for the WPML ones. That didn't help. However the problem is solved when the theme is set to a standard theme.

July 12, 2022 at 12:08 am #11646039

takahiroK-2

Any assistance please

July 12, 2022 at 2:55 pm #11652035

Nigel
Supporter

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

Hi there

I'd like to help, and I think I will need access to your site to be able to check how you have this set up, and to take a look at the theme to see if I can spot what the issue might be.

Let me mark your next reply as private so that we can get log-in credentials from you—you may want to create a temporary admin user for us to use that you can later delete. And be sure to have a current backup of your site.

This is a dev site, yes? It's okay for me to make some temporary changes such as switching theme?

July 13, 2022 at 8:27 am #11656343

Nigel
Supporter

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

Thank you for that.

I'm not sure I understand the problem.

There is an original EN version of the post here: hidden link

That includes several links with EN labels (e.g. "Hotel" and "Hotel sub").

The page is translated to zh-hans here: hidden link

The labels are still in EN, but the links point to zh-hans translations of the links in the EN original.

That is exactly what is shown when editing the translation of the page (screenshot).

The translations have updated links but EN labels, and that is what is output on the zh-hans version of the page.

So it seems to be working correctly.

Am I missing something?

Screenshot 2022-07-13 at 09.21.57.png
July 14, 2022 at 12:14 am #11662673

takahiroK-2

Yes the links are correctly translated on the editing of the translation page. However on the page itself (hidden link)

Hotel is linked as translated to: hidden link

Hotel Sub has also been linked however is jumping to hidden link instead of hidden link

(not 100% sure) This problem seems to be occurring when there are 2 custom post types in the URL. Because the same problem is also occurring with Activity and Activity Sub

July 14, 2022 at 11:27 am #11666053

Nigel
Supporter

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

OK, I copied all of the relevant links into a spreadsheet to be able to compare them side-by-side and I can see that the translated links are not the links being output on the translated page.

Can you go to WPML > Settings and run the scan to update link targets?

Does that fix the problem?

Otherwise I may need some more information about your post types and permalink structures for them.

This is an example of a link that doesn't work, as described: hidden link

I don't understand the URL.

When I edit that post I see that it is off a post type "hotel-info", and when I go to check the settings for that custom post type (created with CPT UI), it's a non-hierarchical post type that doesn't use a custom rewrite slug, so I would expect a URL such as hidden link. I don't understand where the actual URL comes from.

Screenshot 2022-07-14 at 12.20.42.png
July 19, 2022 at 7:05 am #11690301

takahiroK-2

> Can you go to WPML > Settings and run the scan to update link targets?
> Does that fix the problem?

No.
I ran the scan by clicking "Scan now and adjust links" in the Settings page, but, still "Hotel Sub" link in hidden link links to the English page.

The post type URLs are changed in functions.php in our theme files. PHP codes from line 394,
-------------------
function custom_rewrite_hotel_info() {
// add_rewrite_rule('^hotels/[^/]+/([^/]+)/?$', 'index.php?post_type=hotel-info&hotel-info=$matches[2]&taxonomy=hotel-name&hotel-name=$matches[1]', 'top');
add_rewrite_rule('^hotels/(.+?)/(.+?)/?$', 'index.php?post_type=hotel-info&hotel-info=$matches[2]&taxonomy=hotel-name&hotel-name=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_hotel_info');
------------------
is rewriting the urls.

Also, codes before it (line 375) is adding "hotel-name" taxonomy like ".../hotel-kokusai-21/...".

July 19, 2022 at 10:53 am #11692321

Nigel
Supporter

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

I'm sorry, but custom rewrite rules are not something we are able to help with.

I expect that if you disable the custom rewrite rules, update your translations, and—possibly—run the scan again you will find that the links work as expected.

If you need help writing custom rewrite rules that don't break such links in a multilingual context you may want to consult with a developer from https://wpml.org/contractors/

July 21, 2022 at 7:15 am #11706935

takahiroK-2

I assume that disabling the custom rules would affect all the URLS correct?
Is there anyway other way we can fix this problem?

July 21, 2022 at 11:09 am #11709573

Nigel
Supporter

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

I'm not an expert in custom rewrite rules, but it looks to me like you would have to modify the code that hooks into the post_type_link filter (from line 375) which is what modifies the link URLs being output.

Because the translated links are already correct, it seems like you would not need to modify them with this code (which then breaks them).

I suspect that you should be able to skip modifying the link if we are looking at a translation rather than the original.

You could try checking if the current language is the same as the default language (if not then we would be looking at a translation) and only change the link when the current language is the same as the default language.

See https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-605535 and https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-605607

July 28, 2022 at 11:51 am #11758575

takahiroK-2

I added a code "$current_lang = apply_filters('wpml_current_language', NULL); $default_lang = apply_filters('wpml_default_language', NULL ); if ($current_lang == $default_lang && for our filter function of 'post_type_link'. It caused the URL of .../zh-hans/... doesn't be changed like English (default language). I think our codes changing the URLs to /smr/(area term)/ need for all languages.

Then, I commented out our filter hook codes totally and changed to use "Custom Rewrite Slug" of the post type setting (to "smr") and set the permalink of it to "/%area%/%postname%/". However, it causes "Page not found" (404 error) for all pages , such as hidden link. Why?

July 29, 2022 at 8:40 am #11764685

Nigel
Supporter

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

Are we talking about the hotel-info post type?

You are using the CPT UI plugin for registering post types.

Checking the settings, for hotel-info post type it is using the rewrite slug "hotels".

But you already have a custom post type that uses a slug of "hotels", so that may cause problems, they must use distinct slugs.

I see also there is a Destinations post type that has a slug of "smr", so perhaps you are referring to this post type.

According to the post type settings that simply uses the smr slug in its permalinks, and the links work correctly as far as I can see (e.g. hidden link).

I see you are also using the plugin Custom Post Type Permalinks to further modify the permalink structure individually for each post type.

It doesn't make any further changes to the smr permalink structure.

But it does make changes to the permalink structure for the hotels-info post type, to include the hotel-name taxonomy, i.e. hidden link

And trying to visit a hotel-info post at its link such as hidden link produces a page not found.

I suspect that is because according to your post type settings you are using "hotels" both for the hotels post type and as the rewrite rule for the hotel-info post type.

Note that this problem occurs even if you disable WPML.

We can support you with problems with translating your content, but fixing problems with your permalink structures is outside the scope of WPML support, you should really be contacting the authors of the plugins you are using for more help.

Screenshot 2022-07-29 at 09.39.48.png
Screenshot 2022-07-29 at 09.13.46.png
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.