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.

WordPress 6.7 has introduced a new issue that impact translations, please update WooCommerce and WPML to the latest versions before you report issues. More about this here - https://wpml.org/errata/php-error-wp-6-7-notice-function-_load_textdomain_just_in_time-was-called/
Sun Mon Tue Wed Thu Fri Sat
- - 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00
- - - - - - -

Supporter timezone: America/Lima (GMT-05:00)

Tagged: 

This topic contains 0 replies, has 0 voices.

Last updated by Andreas W. 2 days, 11 hours ago.

Assisted by: Andreas W..

Author Posts
November 12, 2024 at 8:32 pm #16394556

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Issue 1: Courses slug is rewritten to prodotto" or "products":

On the staging that I disabled any plugin apart from Learndash and its addons, WooCommerce, SCF, Yoast and WPML and our addons.

The issue disappeared and I was for example able to access an Italian course here:
hidden link

The issue with the slug rewrite to "prodotto" or "product" does not occur again after I enable all the plugins again which is why I can not tell what was causing it.

---

Issue 2: Courses in second language us a wrong slug and display the error TO MANY REDIRECTS:

Once I switch from Astra Child Theme to the Astra Parent Theme the issue disappears.

This issue is caused by code inside your child theme's functions.php file.

I am fully sure what is causing this issue, but it seems to be connected to your custom integration of "Advanced Coupons for WooCommerce" in your Child Theme.

As the issue does not occur using the Parent Theme, this might need to be considered as an issue that occurs due to custom code.

If I comment out this line, the issue even occurs on the original course pages:
// use ACFWF\Models\Third_Party_Integrations\WPML_Support;

This might be something that you need to report to "Advanced Coupons for WooCommerce".

In case you need further assistance regarding this from our site, please explain to me why you are integrating the plugin in this way into the functions.php file of your Child Theme and what you are trying to achieve this way.

November 13, 2024 at 9:26 am #16396086

denyD

Issue n.1:
I would like to clarify that I have always been able to view the course page in Italian; the problem only occurs with the English courses.

In any case, I don’t know if this might help, but I believe that a couple of years ago, an agency that was handling the website may have changed the default LearnDash slug from "/courses/course-category/course-name" to "/i-nostri-corsi/course-category/course-name." I’m not sure if this is relevant or not. By the way, I didn't understand whether you were able to see the English course page with the correct slug or not, which is what I am interested in.

Issue n.2:
I rarely use the plugin in question, and it's not essential, so I could easily disable it—would this resolve the issue? Additionally, I have never modified the code to change anything about the plugin. If you find a solution, feel free to completely remove the plugin and any related code. Feel free to try to disable any active snippet also.

Thank you for your help. I hope to find a solution as soon as possible.

November 13, 2024 at 6:40 pm #16399230

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

The first issue was just related to the slug rewrite, not to CPTs not visible on Frontend. The only workaround I found was setting the site into a minimal setup as explained above and then re-activiating all plugins again.

I wish I could provide you a better workaround for the first issue, but I sadly did not find one. Usually resaving the permalinks in WordPress should have been enough, but not in this case.

For the second issue, please tkae note that our support team is not supposed to troubleshoot custom code issue. I am making an exception in this case.

I have removed the plugin and its related code and relative files from the Child Theme. Take note, that this was not the source of the issue.

Current functions.php file:

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
function gimarbeauty_script() {
    wp_enqueue_style( 'gimarbeauty', get_stylesheet_directory_uri() . 'https://cdn.wpml.org/style.css', array(), wp_get_theme()->Version );
}
add_action( 'wp_enqueue_scripts', 'gimarbeauty_script', 10 );

/* REWRITE RULES FOR SEO BY DAVIDE */
function gimarbeauty_corsi_generating_rule($wp_rewrite) {
    $rules = array();
    $terms = get_terms( array(
        'taxonomy' => 'ld_course_category',
        'hide_empty' => false,
    ) );

    $post_type = 'sfwd-courses';

    foreach ($terms as $term) {    
        $rules['i-nostri-corsi/' . $term->slug . '/([^/]*)$'] = 'index.php?post_type=' . $post_type . '&sfwd-courses=$matches[1]&name=$matches[1]';
    }

    // Merge with global rules
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'gimarbeauty_corsi_generating_rule');

function change_link_corsi( $permalink, $post ) {
    if( $post->post_type == 'sfwd-courses' ) {
        $resource_terms = get_the_terms( $post, 'ld_course_category' );
        $term_slug = '';
        if( ! empty( $resource_terms ) ) {
            foreach ( $resource_terms as $term ) {
                // Skip the 'featured' category to get the main one
                if( $term->slug == 'featured' ) {
                    continue;
                }
                $term_slug = $term->slug;
                break;
            }
        }
        $permalink = get_home_url() . "/i-nostri-corsi/" . $term_slug . '/' . $post->post_name;
    }
    return $permalink;
}
add_filter('post_type_link', "change_link_corsi", 10, 2);

Take note that this code includes:

- A function for enqueuing the parent theme’s stylesheet (gimarbeauty_script)
- Custom rewrite rules for SEO (gimarbeauty_corsi_generating_rule)
- A custom link modification function for course post types (change_link_corsi).

If you now go to hidden link you will still get a TOO MANY REDIRECTS error.

This errors appears to disappear if I disable WPML. I was not able to find a workaround for this and would suggest removing this function.

Take note, that I got stuck testing, as my edits on functions.php seem to have casued a syntax error and I can not access the file manager anymore.

Please remove the last function from the functions.php file of the Child Theme and it should solve the issue.

It is a conflict between WPML and the following function:

function change_link_corsi( $permalink, $post ) {
    if( $post->post_type == 'sfwd-courses' ) {
        $resource_terms = get_the_terms( $post, 'ld_course_category' );
        $term_slug = '';
        if( ! empty( $resource_terms ) ) {
            foreach ( $resource_terms as $term ) {
                // Skip the 'featured' category to get the main one
                if( $term->slug == 'featured' ) {
                    continue;
                }
                $term_slug = $term->slug;
                break;
            }
        }
        $permalink = get_home_url() . "/i-nostri-corsi/" . $term_slug . '/' . $post->post_name;
    }
    return $permalink;
}
add_filter('post_type_link', "change_link_corsi", 10, 2);

If I remove the function, the site operates as expected.

November 13, 2024 at 6:42 pm #16399239

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Take note that editing the functions.php file caused a 500 error and I can not make further edits.

Please remove the last function gimarbeauty_corsi_generating_rule() that I added to functions.php to solve this error.

November 14, 2024 at 9:47 am #16401459

denyD

Okay, I understand everything perfectly. Basically, the team from this agency (which was hired for SEO) changed the course permalinks from 'courses' to 'our-courses,' which creates a conflict. So, this could be resolved by removing that custom code, but at the same time, would my SEO suffer? Is there a way to avoid that? Is this the only solution? Is there a way to make WPML work despite this change?

Anyway, I’ve set up the staging environment, you can continue!

November 14, 2024 at 3:20 pm #16403740

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Now, this is usually out of scope for our support.

We can only support WPML-related issues and this issue is caused by a custom function inside the Child Theme and is altering the permalink behavior of WordPress and WPML.

It is simply that the custom function I mentioned earlier is not designed to work multilingual. It will set the permalink always to:

 $permalink = get_home_url() . "/i-nostri-corsi/" . $term_slug . '/' . $post->post_name;

And /i-nostri-corsi/ will not work if in a second language the slug is "courses" or "our-courses".

You could try instead:

$post_type = 'your_custom_post_type'; // Replace with your original custom post type name
$term_slug = 'your_term_slug'; // Replace with your original term slug
$language_code = apply_filters( 'wpml_current_language', NULL ); // Get the current language code

// Get the translated slug for the custom post type in the current language
$translated_slug = apply_filters('wpml_get_translated_slug', 'your_slug', $post_type, $language_code, 'post');

if ($translated_slug) {
    $permalink = trailingslashit(get_home_url()) . $translated_slug . '/' . $term_slug . '/' . $post->post_name;
}
November 14, 2024 at 3:29 pm #16403827

denyD

Sorry Andreas, but I didn’t understand the purpose of the last code you sent me.

November 14, 2024 at 4:20 pm #16404089

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

The way how this function is designed, it will always set the custom post type slug to "/i-nostri-corsi/" and this causes a conflict, if the slug is translated into something else in a second language.

My suggested fix will check for the slug in a second language and replace it accordingly. It will use the WPML Hook 'wpml_get_translated_slug' for this purpose.

In this case the custom function should look like this to work with WPML and you will get the expected URLs in both languages. Take note that I also translated the slug back to "courses" inside the WPML settings page:

function change_link_corsi( $permalink, $post ) {
    if( $post->post_type == 'sfwd-courses' ) {
        $resource_terms = get_the_terms( $post, 'ld_course_category' );
        $term_slug = '';
        
        // Retrieve the translated slug for the custom post type
        $language_code = apply_filters( 'wpml_current_language', NULL ); // Get the current language code
        $default_slug = 'i-nostri-corsi'; // Default slug in your primary language
        $translated_slug = apply_filters( 'wpml_get_translated_slug', $default_slug, 'sfwd-courses', $language_code, 'post' );

        if( ! empty( $resource_terms ) ) {
            foreach ( $resource_terms as $term ) {
                // Skip the 'featured' category to get the main one
                if( $term->slug == 'featured' ) {
                    continue;
                }
                $term_slug = $term->slug;
                break;
            }
        }

        // Build the permalink with the translated slug
        $permalink = trailingslashit(get_home_url()) . $translated_slug . '/' . $term_slug . $post->post_name;
    }
    return $permalink;
}
add_filter('post_type_link', "change_link_corsi", 10, 2);

This appears to solve the issue.

Please take kindly note again, that our supporters usually are not supposed to provide any custom code solutions and I made an exception here.

This is a developer topic and in such case you usally should reach out to one of our contractors:
https://wpml.org/contractors/

November 14, 2024 at 4:21 pm #16404090

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

The way how this function is designed, it will always set the custom post type slug to "/i-nostri-corsi/" and this causes a conflict, if the slug is translated into something else in a second language.

My suggested fix will check for the slug in a second language and replace it accordingly. It will use the WPML Hook 'wpml_get_translated_slug' for this purpose.

I might a slight adjustment to the earlier provided function, as it was adding one "/" too much. In this case the custom function will get the expected URLs in both languages. Take note that I also translated the slug back to "courses" inside the WPML settings page:

function change_link_corsi( $permalink, $post ) {
    if( $post->post_type == 'sfwd-courses' ) {
        $resource_terms = get_the_terms( $post, 'ld_course_category' );
        $term_slug = '';
        
        // Retrieve the translated slug for the custom post type
        $language_code = apply_filters( 'wpml_current_language', NULL ); // Get the current language code
        $default_slug = 'i-nostri-corsi'; // Default slug in your primary language
        $translated_slug = apply_filters( 'wpml_get_translated_slug', $default_slug, 'sfwd-courses', $language_code, 'post' );

        if( ! empty( $resource_terms ) ) {
            foreach ( $resource_terms as $term ) {
                // Skip the 'featured' category to get the main one
                if( $term->slug == 'featured' ) {
                    continue;
                }
                $term_slug = $term->slug;
                break;
            }
        }

        // Build the permalink with the translated slug
        $permalink = trailingslashit(get_home_url()) . $translated_slug . '/' . $term_slug . $post->post_name;
    }
    return $permalink;
}
add_filter('post_type_link', "change_link_corsi", 10, 2);

This appears to solve the issue.

Please take kindly note again, that our supporters usually are not supposed to provide any custom code solutions and I made an exception here.

This is a developer topic and in such case you usally should reach out to one of our contractors:
https://wpml.org/contractors/

November 14, 2024 at 4:25 pm #16404123

denyD

Thank you so much, Andreas. So you're telling me that you’ve already tested the code and it works? Can I go ahead and replace the custom code they implemented on the original site with this? Also, can you assure me that this won’t negatively impact my SEO?

November 14, 2024 at 5:02 pm #16404348

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Yes, this is implemented on your staging site and can be tested there. Please compare the results with your live site.

I would defenitely suggest applying this fix, as the fact that the site URLs were not created correctly is even worst for SEO.

November 15, 2024 at 10:35 am #16407218

denyD

Thank you, Andreas, but there is still an issue. Now the English course pages are visible, but the Italian course pages are no longer visible in staging. Do you know what happened?

November 15, 2024 at 5:54 pm #16409499

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

The English course is available:
hidden link

The issue appears to be that inside the WPML language switcher the language directory is missing.

It is realted to the changes inside the functions.php file fo the Child Theme. Take note again, that the original code here was not considering that the site is multilingual. I tried fixing this using WPML compatilbity code, but it is not fully working.

Until now I was not able to find a solution for this. I can offer to give it a nother try later today but I can not promise at this moment to find a working solution.

Further, I am not able to escalate this issue to Second Tier, as it is not a WPML issue and only occurs because of the custom code inside the Child Theme.

I would suggest you consider to consult one of our contractors:
https://wpml.org/contractors/

November 15, 2024 at 5:58 pm #16409502

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

I would need FTP access to the staging site, as disabling plugins triggered a fatal error.

The private reply form is enabled again.

November 18, 2024 at 3:45 pm #16415649

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

It would be generally advisable to reach out to the contractors in such cases.

Our support does not have the capacities for debug and fix issues that occur due to custom code. The custom code on your theme was not coded in a way that it could work with WPML.

I can offer to have another look into this, but take note that the time that we can dedicate on each ticket per time is limited and I can not promise to have a quick solution for you.

I can currently not access your site, as possibly disabling "Secure Custom Fields" triggered an error in the child theme.

This usually happens if the child theme calls ACF Fields and does not validate if SCF is active or not - it is a common developer mistake.

I could fix this issue, by uploading a file to the server that allows me to access the database and then activate a different theme by changing the option value manually.

Would you agree on that?