Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The theme supports changing the CPT slug in the URL (rewrite), after that, the translation page is not working.
Solution:
Use the PHP code to flush the rewrite rules

function wpml_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action( 'init', 'wpml_flush_rewrite_rules', 20 );

Relevant Documentation:
https://wpml.org/documentation/support/translating-slugs-for-custom-post-type-archives/#troubleshooting-customizable-slugs

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 6 replies, has 3 voices.

Last updated by rinkd 1 year, 9 months ago.

Assisted by: Long Nguyen.

Author Posts
April 10, 2023 at 10:26 am #13436819

rinkd

Dear support team,

I am running a website where users can add properties in Dutch. I am translating it in English using WPML, and I am almost done.

The theme that I am using uses a post type /panden/ (properties in Dutch) in the URL slug. Unfortunately this is not translatable (I have checked here in a previous ticket but also with the theme authors). Therefore, I want to use a slug that can both be applied in Dutch and English, which is /items/.

Changing /panden/ to /items/ works great on the Dutch website. I have also added the following code in my .htaccess to make sure Google clicks lead to the correct properties.

RewriteEngine On
RewriteRule ^panden/(.*)$ /items/$1 [R=301,L]

However, the new slug does not work correctly on my wpm domain. Clicking any property still leads me to the url with /panden/, which then shows an 404 error since the property is not there.

I have cleared the WPML cache and saved permalink, but I cannot get it to work. Could I please make use of your expertise to know what the problem is and how this can be fixed?

Please note: I have reverted all changes back, so the English website at least works!

Thank you for your time and efforts.

Best regards,
Ali

April 10, 2023 at 1:26 pm #13437471

Andreas

Hi,

before your ticket is assigned to one of my colleagues, please allow me to walk you through some initial debugging steps. This will help speed up the support process.

Translating slug from custom post type archive needs to be done from the theme authors because it needs to be set as translated. Otherwise, you need a custom code to do it.

You can read more here :
https://wpml.org/documentation/support/translating-slugs-for-custom-post-type-archives/

Regards,
Andreas

April 10, 2023 at 6:21 pm #13439475

rinkd

Dear Andreas,

Thank you for your response. I think because I may have put too much information in my initial post, my point was unclear. It is not that I want to translate the custom post type. I will try to explain better below.

Current situation
Right now, on both my Dutch website and WPML English website I use the post type /panden/. So let's say hidden link and hidden link. This works perfectly fine!

Ideal situation, which does not work
I wanted to keep /panden/ on the Dutch website and /properties/ on the English. WPML and the theme authors concluded that this indeed does NOT work with my theme. But this is not a problem, because of my solution below.

Solution, that does not fully work and I am opening this ticket for
I have now changed the slug from /panden/ to /items/ in my Theme (the same way I have set it to /panden/, it is just a setting), which should be effective on both the Dutch and English website. So, exactly like the current situation, I would expect it to be hidden link and hidden link. However, now it does not work.
It seems like the main/Dutch website sees this change and it works good there. However, the English/WPML domain still has all links there with /panden/. So, the links did not even update, even not when I hover my mouse on the properties.

I am wondering if it is a cache issue in WPML or that there is some other setting in WPML that I am missing to reindex the links. I hope with your expertise I can find and solve this issue.

Thank you for your time and efforts.

Best regards,
Ali

April 11, 2023 at 2:52 am #13441195

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi there,

Thank you for contacting WPML support, I'd be happy to help you with this issue.

Checking the Debug Info, I see the default custom post type slug is "estate" but the slug in the URL is "panden". So does the theme support an option to change the CPT slug (rewrite)?

If yes, please try to use the workaround below and see if it helps:

- Edit the file functions.php in the theme/child theme folder

- Add the code to flush the rewrite rules

function wpml_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action( 'init', 'wpml_flush_rewrite_rules', 20 );

❌ IMPORTANT: Please backup your database and website before proceeding ❌

- Remove the code in the file .htaccess

Then you can go to WPML > String Translation > Search for the slug "panden" and translate it. Please read more in the documentation https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/

Look forward to your reply.
Thanks

April 11, 2023 at 5:34 pm #13449075

rinkd

Hi Long Nguyen,

Correct, the theme has an option to change the CPT slug.

Thank you so much for your response and piece of code. It works! Now the English/WPML also shows /items/. So, both the Dutch and English website use /items/ now instead of /panden/.

However, all my Google search results still point to the URL's with /panden/, therefore giving an error 404. Since you state to remove the code in my .htaccess, how can I let these results point to all URL's with /items/ instead of /panden/, and make them work again? I have also tried it with my .htaccess code, but it does not seem to work.

Thank you for your time and efforts.

Best regards,
Ali

April 12, 2023 at 3:08 am #13451463

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

I think it could be a caching issue on Google search results. From WPML side, we cannot tell Google to index or crawl things on your site. You can try to follow the documentation below to ask Google to recrawl your site URLs.
hidden link

Also, the theme MyHome is not available in our list of compatible themes, which you can check here https://wpml.org/theme/. And the snippet code above is a workaround to fix the issue temporarily. I recommend contacting the theme author to ask for a long-term solution and ask them to join our Go Global program where our Compatibility developers will help them to make their product compatible with WPML.
https://wpml.org/documentation/support/go-global-program/

Look forward to your reply.
Thanks