This thread is resolved. Here is a description of the problem and solution.
Problem: The client is experiencing issues with creating English courses using Learndash on an Italian website. The permalinks for the courses are incorrect and not translated, leading to 404 errors and too many redirects. Solution: 1. Ensure that Learndash is translated using the WordPress Editor. For more details, visit https://wpml.org/plugin/learndash-lms/. 2. Duplicate the course with WPML and set it as independent. Adjust the permalink settings in WordPress and translate the slug in WPML > Settings > Post Type Translation. 3. Take note, that this issue was related to custom code in the child theme's functions.php file and we provided a workaround for the issue. 5. Verify that the custom post type slug is translated in WPML > Settings > Post Type Translation. For more information, visit https://wpml.org/documentation/getting-started-guide/translating-page-slugs/.
If these steps do not resolve your issue, or if the solution seems outdated or irrelevant to your specific case, we recommend opening a new support ticket. Additionally, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. For further assistance, visit our support forum.
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.
Hi Andreas, I'm not entirely clear on what you're trying to do, but if this won't cause any issues or blocks on the main site, feel free to proceed as you prefer!
Sorry, Andreas, I had the code analyzed by ChatGPT to understand if it could affect my Italian SEO, and this is what it says:
Analyzing the new code provided, it appears to address the issue in a robust manner. However, there are some critical aspects that need to be reviewed to ensure it fully meets your requirements. Let’s break it down:
What the new code does:
Handles the translated slug for the custom post type (sfwd-courses):
It uses the wpml_get_translated_slug filter to fetch the translated slug based on the current language.
It provides a fallback to retain the original slug (e.g., i-nostri-corsi) if a translation is not available.
Builds the permalink:
Combines the translated slug, the category term (ld_course_category), and the post name (post_name).
Avoids errors with fallbacks and sanitization:
Ensures each component of the permalink is properly defined, avoiding malformed URLs or double slashes (//).
Potential issues or uncertainties:
Italian language:
While the code seems to handle Italian correctly, it doesn’t explicitly ensure that the original slug /i-nostri-corsi/ remains unchanged for Italian courses. If wpml_get_translated_slug returns a different slug for Italian, it might unintentionally alter the permalink.
Incomplete slug translation:
The fallback uses $default_slug (i-nostri-corsi) if no translation is found. However, this might not be sufficient in edge cases (e.g., if the translated slug is empty or differs from what you expect).
SEO impact:
The code should preserve existing permalinks in Italian, but if the slug changes for any reason, it could break existing URLs.
Expected outcomes:
If your goal is to:
Italian language: Keep the original /i-nostri-corsi/ slug intact.
Other languages: Translate the slug appropriately based on WPML settings.
The code will work only if:
The Italian slug (i-nostri-corsi) is explicitly preserved.
WPML is correctly configured to handle translations for the other languages
Possible improvements:
To ensure the Italian slug is never altered, you can explicitly enforce it in the code:
if ( $language_code === 'it' ) {
$translated_slug = $default_slug; // Keep the original slug for Italian
} else {
$translated_slug = apply_filters( 'wpml_get_translated_slug', $default_slug, 'sfwd-courses', $language_code, 'post' );
}
This ensures that for Italian, the slug always remains i-nostri-corsi, regardless of WPML’s configuration.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Yes, this is correct and the findings of ChatGPT appear expected..
If you change the original Italian slug, this snippet will not longer work. Further, it is expected that WPML changes the slug accordingly to use the translated slugs in other languages.
I need to point out again, that I did already way more than expected here.
Custom code requestes are not covered by our support policy and our supporters are not supposed to provide custom code solution.
You could consult ChatGPT about how to obtain the original CPT slug dynamically and also ask it to handle edge cases in which a translation does not exists. It should come up with a working solution.
If you would like someone else to optimize your custom code, then I need to ask you reach out to on of our contractors: https://wpml.org/contractors/
I switched the code from staging to live, and there’s only one difference: in the staging environment, when I open a course in English, after /en/ there’s courses, while in the live environment, it still shows i-nostri-corsi. Could you explain why?