Skip to content Skip to sidebar

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-06:00)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by Ilyes 1 year ago.

Assisted by: Ilyes.

Author Posts
July 11, 2024 at 1:27 pm #15934704

emanueleP-14

Background of the issue:
I am trying to: `lang` url parameter disappears from URL in address bar after I click `Update`/`Save draft` on a post edit page. This is related to the fact that the language specified in `lang` parameter gets written to cookies. Link to a page where the issue can be seen: hidden link

Symptoms:
As result, when working with different languages in multiple tabs at the same time and reloading a post edit page, I get categories in a wrong language.

Questions:
Why does the `lang` URL parameter disappear from the URL in the address bar after I click `Update`/`Save draft` on a post edit page?
How can I prevent the `lang` URL parameter from disappearing to ensure the correct language categories are displayed?

July 11, 2024 at 2:36 pm #15935906

emanueleP-14

I didn't see a way to upload a video here. So I uploaded it to my Google Drive and sharing the link to the file with you: “deleted”

Let me know if you can access it and please download it so I can remove it asap.

July 11, 2024 at 4:31 pm #15936587

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

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

Hello,

Yes, you can delete it now,

I will keep you updated!

July 12, 2024 at 3:54 pm #15943317

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

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

Hello,

So I tried to replicate the issue on a new installation, you can access it from here : hidden link

Please watch this video to show you that the issue got replicated but there wasn't a clear pattern : hidden link

Could you please try replicating the issue yourself or maybe find an idea on what I'm missing, or if it is totally random?

In the meantime, I have shared all this information with our 2nd tier team, I will let you know if they found a solution,

Best,

July 13, 2024 at 9:57 am #15947023

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

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

Hello,

I have got an answer from our team,

This issue happens because:

    Default language is a custom language
    The Category Base Slug was not assigned to the site default language
    The Category Base Slug was not translated

To solve this, go to WPML > Taxonomy Translation > Translations of taxonomy Category labels and slug :

1- Assign the Base Slug to the Site Default Language
2- Translate the Slug

Please let me know if this helped,

Best,

July 16, 2024 at 10:37 am #15959814

emanueleP-14

Hello,

Sorry for the late reply. But here is a bit more details.

First of all, it's not random. I can easily replicate the issue in the test environment that you shared.

Maybe I didn't show it clearly enough but here are the steps to replicate the issue:
1) Open 2 posts in two different languages in 2 different tabs.
2) Click update on the first post edit page (`lang` parameter is gone)
3) Just refresh the edit page of the second post (don't click "Update", `lang` parameter is still there)
4) Go back to the first post edit age and just refresh the page and you will see the categories for a language that the second post is in.

----------------------------------------------------------------

In relation to the suggested solution, I believe we already have a category base slug assigned to the site's default language as well as the category base slug is translated into all other custom languages. Attaching two screenshots that demonstrate this.

Please correct me if the screenshot don't confirm this.

Also, did you try the steps recommended by your 2nd tier team? Did it help?

Screenshot 2024-07-16 at 13.32.18.png
Screenshot 2024-07-16 at 13.32.08.png
July 16, 2024 at 11:10 pm #15962965

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

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

Hello,

Yes, I did try the solution and since I didn't have the clear steps to test this correctly, I assumed it was working,

So I went ahead and found out that this doesn't help to solve the problem, so I escalated it back again,

Finally, do you think we can get a duplicator copy of your site rather than the access? I remember you said we can't access your site because of the company VPN, so a copy is useful here,

This will allow our team to test future workarounds directly on your site, and avoid future delays,

I will open a private field for your next reply in case you can upload it (please exclude media files).

Best,

July 23, 2024 at 1:43 pm #15992591

emanueleP-14

Hello,

The way we perform deployment is not very standard and it would require some effort to get a copy of our WP running in your environment. Simply saying we can't easily archive everything and share it. At the same time, I don't see any benefits of doing it right now as the issue can be easily reproduced in the sandbox environment that you shared with me previously. So I'm not going to spend time on this for the moment.

Please, let me know if I can help in any other way or there are some updates.

Best

July 23, 2024 at 2:42 pm #15992954

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

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

Hello,

Thank you for your patience,

So after checking the logic behind this behavior, we found multiple key points you need to consider before applying this workaround :

1- This code might not work as the logic that removes the parameters is deeply embedded in React and happens client-side, aka, it is related to how WordPress Gutenberg Editor work and not related to WPML.

2- The only editor we could tweak without affecting your site and WPML functionality, is the Classic Editor, hence, if you think you can switch to that version, you could apply the workaround below.

3- You can test it out on the sandbox here first : hidden link

4- This is why for translations we offer Classic Translation Editor and Advanced Translation Editor and they will avoid that WordPress limitation.

5- With all that said, here is the workaround that I applied to the sandbox :

The fix for this issue would be to make sure that this lang parameter remains on the URL when clicking Update. Still, as this is calling the native save_post() method, we would need to hook into WordPress default behavior to maintain the lang parameter in place.

Example: /wp-admin/post.php?post=66&action=edit&lang=en-us

After doing a backup, add this function to the theme's functions.php file:

// Add lang parameter on post edit screen
function add_language_to_edit_url_wpml($post_id) {

    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    // Get current language code
    $wpml_language_info = apply_filters('wpml_post_language_details', null, $post_id);
    if (!$wpml_language_info) {
        return;
    }
    $wpml_language_code = $wpml_language_info['language_code'];

    $current_url_wpml = admin_url();

    $new_url_wpml = $current_url_wpml . 'post.php?post=' . $post_id . '&action=edit&lang=' . $wpml_language_code;

    if ($post->post_status === 'publish' || isset($_POST['save'])) {
        wp_redirect($new_url_wpml);
    exit;
    }
}
add_action('admin_init', 'add_language_to_edit_url_wpml', 10, 1); 

I hope this helped,

Best,

The topic ‘[Closed] `lang` url parameter disappears from URL in address bar after I click `Update`/`Save draft` on a pos…’ is closed to new replies.