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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 15:00 7:00 – 15:00 7:00 – 15:00 7:00 – 15:00 7:00 – 15:00 -
- - - - - - -

Supporter timezone: Pacific/Easter (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Ilyes 2 months, 2 weeks ago.

Assisted by: Ilyes.

Author Posts
August 15, 2024 at 1:50 pm

simonS-80

Background of the issue:
I have the Language URL format set to Language name added as a parameter (hidden link - English).

Symptoms:
It's not honouring this on all my pages. Because of this some pages are broken.

Questions:
Why is the Language URL format not being honoured on all my pages?
How can I fix the broken pages caused by the incorrect Language URL format?

August 15, 2024 at 2:52 pm
August 16, 2024 at 4:03 pm #16078864

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello again,

So I have found out that this parameter is being added through a custom code that maybe you or the previous developer added under your theme's functions.php file :

add_action('init', function () {
    global $wp_post_types;
    foreach (get_post_types() as $post_type) {
        if ($wp_post_types[$post_type]->public && !$wp_post_types[$post_type]->show_in_rest) {
            $wp_post_types[$post_type]->show_in_rest = true;
            if (empty($wp_post_types[$post_type]->rest_base)) {
                $wp_post_types[$post_type]->rest_base = $wp_post_types[$post_type]->name;
            }
        }
    }

    global $sitepress;
    $siteLang = 'nl';
    if (isset($_GET['language__'])) {
        $siteLang = $_GET['language__'];
    }
    if ($siteLang == 'fr') {
        $sitepress->switch_lang('fr');
    } else {
        $sitepress->switch_lang('nl');
    }
}, 40000);


function add_query_vars_filter($vars)
{
    $vars[] = "language";
    $vars[] = "page";
    return $vars;
}
add_filter('query_vars', 'add_query_vars_filter');

I had to escalate this to our developers to review your code and if it is possible and safe to add the language name for default language.

By default this option is not available, I'm yet to receive an answer about the logic behind this, so I will keep you updated once I receive an answer,

And please keep in mind that usually, we do not offer support for custom codes, but I could at least guide you on how you could solve this,

Best,

August 25, 2024 at 10:44 pm #16102128

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello,

For this issue, a redirection is coming from a redirection plugin or custom code on the default language, here is a screenshot : hidden link

Since language__ is not a valid parameter for WPML, WPML ignores it and displays the default language without the language code.

For French I saw they are first loading /?lang=fr the page and then just pushing the state in history with language__ to change the URL in browser. However, this is not the correct approach.

I would suggest again to use the existing WPML option to use default language in directory and redirect existing URLs to updated URLs with 301.

I'm afraid that this issue falls outside of our support service if you want a custom code, you got to check whoever set this up at first,

Best,

The topic ‘[Closed] WPML not honouring language URL format’ is closed to new replies.