Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing an issue with the BetterDocs plugin on a multilingual site using WPML. When attempting to switch languages on a specific page, the redirection fails, stopping at an intermediate page instead of reaching the correct translated page. This issue is observed with incorrect URLs being generated for language switches.

Solution:
We recommend modifying the BetterDocs plugin code to ensure correct URL generation when switching languages. Here are the steps:
1. Open the file

wp-content\plugins\betterdocs-pro\includes\class-multiple-kb.php

.
2. Locate the function

doc_category_link

around line 695.
3. Replace the existing code with the following snippet:

public static function doc_category_link($termlink, $term, $taxonomy)<br />{<br />    if ($taxonomy != 'doc_category') return $termlink;<br /><br />    $kb_slug = self::kb_slug();<br /><br />    // WPML Workaround for compsupp-6478<br />    if (class_exists('SitePress')) {<br />        $kb_arr = get_term_meta($term->term_id, 'doc_category_knowledge_base', true);<br />        $kb_slug = $kb_arr[0];<br />    }<br /><br />    if (empty($kb_slug)) {<br />        $category = get_term_by('slug', $term->slug, $taxonomy, ARRAY_A);<br />        $kb_arr = get_term_meta($category['term_id'], 'doc_category_knowledge_base', true);<br /><br />        if (empty($kb_arr[0])) {<br />            $kb_slug = 'non-knowledgebase';<br />        } else {<br />            $kb_slug = $kb_arr[0];<br />        }<br />    }<br /><br />    return str_replace('%knowledge_base%', $kb_slug, $termlink);<br />}

This modification should correct the URL generation issue. If this solution does not resolve your problem, or if it seems outdated or irrelevant to your case, please visit our support forum to open a new ticket. We also highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins.

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.

Tagged: 

This topic contains 44 replies, has 2 voices.

Last updated by Osama Mersal 2 years ago.

Assisted by: Osama Mersal.

Author Posts
October 31, 2022 at 3:59 pm #12344565

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Our partnership team will contact the plugin author, and I'll get back to you as soon as we get a reply.

Thanks for your patience

Best regards,
Osama

October 31, 2022 at 10:08 pm #12346161

alexeyK-12

hidden link

look this

November 1, 2022 at 6:35 am #12346965

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

1) Thanks for your reply. The old sandbox is expired because the ticket was closed due to inactivity.

2) The issue was not replicated on the sandbox because you had another urgent issue.

3) Our partnership team contacted the plugin author regarding this issue and waiting for his reply. I'll update you here as soon as I get their reply.

Thanks for your patience

Best regards,
Osama

November 1, 2022 at 7:32 am #12347047

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

The plugin author provided us with a pro license to test the issue. I tried to replicate the issue, so please check the sandbox site and let me know if that is the same issue you face.

The knowledgebase slug is not translated correctly when switching the language. Kindly check the following pages and try to switch the language.

1) hidden link

2) hidden link

You will notice that the [kb1-es] is not changed to [kb1]. The same happens when switching from English to Spanish.

Best regards,
Osama

November 3, 2022 at 5:55 am #12367841

alexeyK-12

Hello)
Do not quite understand...
I recorded a video for you, which in my opinion can be a step towards solving the original problem.
I don't understand how I can match a similar problem or not...on your site (maybe yes..similar).

Perhaps the links (in my video, when I go to another level) are somewhere else formed ... and they need to be changed?

P.S.
this link: hidden link
gives the following error: hidden link

November 3, 2022 at 6:09 pm #12373959

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

1) I think the video URL is missing from your previous reply. Could you please send it again?

2) Please check the pages on the sandbox and let me know if you face the same issue. I fixed the fatal error.

Best regards,
Osama

November 3, 2022 at 11:06 pm #12375139

alexeyK-12

1. Here is a video everything where you can see that we did as you asked hidden link
Did not help.

2. as you see in the video... a similar problem as on your sandbox site when clicking on the buttons (with a link)
When changing the language, we are simply thrown to a higher level, and not left on the same page simply with a change in language.

And we still created a test site.
Here you can test everything you need.
I'll send you a private message.
Give me that opportunity.

November 4, 2022 at 9:14 pm #12386183

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for your update. I've just received our compatibility team's reply. They have found a workaround by the following steps.

1- Open the (wp-content\plugins\betterdocs-pro\includes\class-multiple-kb.php) file
2- Replace the following snippet (around line 695):

public static function doc_category_link($termlink, $term, $taxonomy)
	{
        if ($taxonomy != 'doc_category') return $termlink;

        $kb_slug = self::kb_slug();

		if (empty($kb_slug)) {
			$category = get_term_by('slug', $term->slug, $taxonomy, ARRAY_A);
			$kb_arr = get_term_meta($category['term_id'], 'doc_category_knowledge_base', true);

			if (empty($kb_arr[0])) {
				$kb_slug = 'non-knowledgebase';
			} else {
				$kb_slug = $kb_arr[0];
			}
		}

        return str_replace('%knowledge_base%', $kb_slug, $termlink);
	}

With:

public static function doc_category_link($termlink, $term, $taxonomy)
	{
        if ($taxonomy != 'doc_category') return $termlink;

        $kb_slug = self::kb_slug();

		// WPML Workaround for compsupp-6478
		if (class_exists('SitePress')) {
			$kb_arr = get_term_meta($term->term_id, 'doc_category_knowledge_base', true);
			$kb_slug = $kb_arr[0];
		}

		if (empty($kb_slug)) {
			$category = get_term_by('slug', $term->slug, $taxonomy, ARRAY_A);
			$kb_arr = get_term_meta($category['term_id'], 'doc_category_knowledge_base', true);

			if (empty($kb_arr[0])) {
				$kb_slug = 'non-knowledgebase';
			} else {
				$kb_slug = $kb_arr[0];
			}
		}

        return str_replace('%knowledge_base%', $kb_slug, $termlink);
	}

I've applied this workaround to the sandbox. Kindly check and let me know if that fixed the issue on the sandbox.

Thanks for your cooperation and patience

Regards,
Osama

November 4, 2022 at 10:35 pm #12386259

alexeyK-12

I passed it on to our specialist.

Although I don't understand...about the sandbox...
I can give you access to the test site we set up.
You will have the opportunity to completely create and test everything yourself without any problems, as our knowledge may not be enough.

November 4, 2022 at 10:38 pm #12386261

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Kindly let me know the result of applying the workaround on your staging site. If it doesn't fix the issue, I'll enable the private reply, so you can share the access details safely.

Thanks,
Osama

November 8, 2022 at 2:19 pm #12411249

alexeyK-12

Osama, hi. You are a genius.
Thank you very much for solving such an important and long-standing problem.
Here is a video where everything works: hidden link (5 days available). Look at the ending of Guide and Guides, why is it one moment one thing and another another moment another?

BUT THERE ARE MORE QUESTIONS
You recommended this to us earlier: https://wpml.org/forums/topic/language-switcher-not-working-properly/page/2/#post-12028837
we did it.

Can we return everything as it was before the implementation of these recommendations of yours? Or if we return that switching of language will not work?

November 8, 2022 at 11:57 pm #12414515

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

1) Thanks for your update. It's great to hear that everything is working correctly. The guide and guides slugs are different because the guide page's slug is "guides" while the knowledgebase slug is "guide".

2) Please take a backup and return the things as you wish and test if they will work correctly.

Best regards,
Osama

November 14, 2022 at 12:15 am #12449427

alexeyK-12

in the process

November 14, 2022 at 12:08 pm #12453639

alexeyK-12

Hey Osama.
We got everything back
https://wpml.org/forums/topic/language-switcher-not-working-properly/page/2/#post-12028837
tested and switching languages (pages) works even without changing the Guide slug to Guides
hidden link
It turns out the question is closed))
Thanks

November 14, 2022 at 12:23 pm #12453861

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

It's great to hear that the issue is fixed now. Please don't hesitate to open a new ticket if you face any issues in the future.

Have a nice day!

Best regards,
Osama