[Resolved] Switcher links are pointing to same url
This thread is resolved. Here is a description of the problem and solution.
Problem: The client was experiencing an issue where the language switcher in the menu was not correctly pointing to the respective language versions of the pages. In some cases, both PT (Portuguese) and EN (English) links were pointing to the English version, despite having both language versions of the pages available.
Solution: 1. We asked the client to provide examples of the pages where the issue occurred and to upload screenshots showing the translation settings for these pages. 2. We inquired if the issue persisted when all other plugins were deactivated, leaving only WPML active. 3. We checked if the Custom Post Type (CPT) was made translatable in WPML → Settings → Custom post translation and if the specific custom post was translated. 4. We requested information on how the CPT was created and suggested testing the language switcher in the footer to see if the same issue occurred. 5. We advised the client to test passing a non-variable to the 'rewrite' argument in their CPT definition:
'rewrite' => array('slug' => 'book'),
If you're experiencing a similar issue, we recommend following these steps to diagnose and resolve the problem. However, please note that the solution might be irrelevant due to being outdated or not applicable to your case. We highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket with us.
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.
I've made the switcher link to apply to my menu, with two languages PT and EN
On many pages the switcher is working correctly: PT is linking to Portuguese versions, and EN to English's.
But in some special cases PT points to EN, as well as the EN link.
Thank you for providing additional information. I understand the issue you are facing now.
Have you made your Custom Post Type (CPT) translatable in WPML → Settings → Custom post translation? Have you translated a particular custom post?
Could you please also explain how you created your CPT? Additionally, what would happen if you temporarily added the language switcher to the footer in WPML > Languages? Do you see the same behavior?
I have the "Post Types Translation" for "filmes" and "pessoas" set to "Translatable
use translation if available or fallback to default language".
You may confirm in the attached image.
I've created my CPT as a plugin, with the following settings:
$filmes_rewriteCPT = array(
'slug' => 'filmes',
'with_front' => false,
);
I've activated the Switcher at the Footer and is working correctly! Why is this happening this way? I need the header switcher not in the footer!
About the Rewrite:
- if you noticed the CPT code above is divided in two parts: the rewrite which has two arguments, the 'slug' and 'with_front'. The rewrite is then called in next args part. So the suggestion you pointed about the slug is already done in the code.
Thank you for the update. I suspect an issue with the language switcher in the menu, as the default in the footer works as expected. How did you add it to the menu?
I won't take your time any longer.
I found the solution.
The switcher was being added to the main menu which was a PT version of it. For some reason it didn't understand that there was a second language for the link.
So I added the switcher using a widget to the same header, then I styled it and it is working.
If you know any solution for this buggy menu just let us know.
I'm happy to hear that the issue has been resolved. As I suspected, it was related to the language switcher. If you have any new questions, please open a new ticket for each question. Have a wonderful weekend!
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.