Skip Navigation

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

Problem:
Syntax error, unexpected "&" and/or unxexpected "if" when using WPML with Elementor PRO.

Solution:

A workaround was provided and the issue solved in upcoming WPML update:

Set post/page/CPT (whichever has the problem) to translatable only
OR
Call the menu in template file or widget do not use page builder
OR
Add this code to functinos.php

add_filter('nav_menu_link_attributes', function ($atts, $item){
    if (isset($item->object) && $item->object == 'wpml_ls_menu_item') {
	$classes = !empty($atts['class']) ? $atts['class'] . ' ' : '';
	$atts['class'] = $classes . 'wpml-ls-link';
    }
    
    return $atts;
},99,2);

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.

Our next available supporter will start replying to tickets in about 5.45 hours from now. Thank you for your understanding.

This topic contains 14 replies, has 2 voices.

Last updated by lucB-14 4 years, 11 months ago.

Assisted by: Andreas W..

Author Posts
December 2, 2019 at 6:31 pm #5056193

lucB-14

Hello, here's my issue.

I am trying to: Switch from one language to another while on different pages than Homepage

Link to a page where the issue can be seen: hidden link

I expected to see: For example, the french translation if I click on the french language on the switcher

Instead, I got: The same English language

The switcher is working but only on the HOMEPAGE and then I can navigate through the website properly. But if I want to switch the language on another page, it's not working.

What I've already tried :
- Deactivate all the plugin not related to WPML
- Use the troubleshooting page to "clean" everything"
- Rise the WP memory to 256 MB

I'm looking forward to getting your advice.

December 2, 2019 at 6:59 pm #5056395

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

I would like to request temporary access (wp-admin) to your site to take a better look at the issue.

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok with you.

IMPORTANT

Please make a backup of site files and database before providing us access.
If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this:
hidden link

Kind regards
Andreas

December 3, 2019 at 3:19 pm #5062285

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

This issue seems to be related to the theme and the menu language switcher.

I have enabled a language switcher for the footer and if you go to hidden link you can see that the redirect is working as expected.

You can disable this language switcher at WPML -> Languages.

Now, we do have two options. We can try to recreate the issue on a new install and check if we run into the same problem when using the menu language switcher. Then I could escalate the issue to our compatibility who will try to solve the issue and reach out to the theme author.

Here a link to a test-site. Please install the theme here and add any plugins that are coming with the theme, if applicable.

One-Click Login: hidden link

Leave me a short notification once the site is ready.

An alternative that would solve the issue quicker would be to use our WPML Custom Language Switcher instead.

More information about how to use the custom language switcher can be found here:
https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

Let me know if you do have any questions.

Kind regards
Andreas

December 4, 2019 at 7:39 am #5065641

lucB-14

Hello Andreas,

I installed the theme and all the plugins in the test-site.

I checked out the Custom Language Switcher but do not have enough skills in coding to handle it properly.

I hope the first option will work out.

Thanks again for your help.

December 5, 2019 at 2:47 am #5073187

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

The issue is not appearing on the new test-site. The WPML Menu language switcher works here as expected.
I tested with additional pages created with Elementor and without. Everything was working like expected.

Now, when connecting to your server I do not fin any .htaccess files which make me think that this might not be the source of the issue.

Further, I tried to run a debug on your live site but did not find any error. A debug.log was not created and no errors displayed.

For now, please try to translate all pages and use WPML -> WP Menus Sync.

As you can see here the translations are working:
hidden link

The issue is related to the menu and its language switcher.

In order to enable a custom language switcher you will need to create a copy of the original header.php file inside of your child theme and place the language switcher by using:

<?php do_action('wpml_add_language_selector'); ?>

I already copied the header.php to the child theme but the Custom Language Switcher is not showing up.
Now, that I have been checking your live site again it seems I found the solution. You are using Elementor Templates, which are not translated yet.

Please translate the templates, especially those related to the header and the navigation and let me know if the issue persists. (Dashboard -> Templates)

Kind regards
Andreas

December 6, 2019 at 9:00 am #5082023

lucB-14

Hi Andreas,

I translated every page and the Elementor header template. I also re-sync the menu but it seems that the problem persists.

I also tried to change the theme but nothing worked. I'm afraid we cannot find a solution.
What else could I do?

December 6, 2019 at 10:33 pm #5086173

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

The issue is somehow linked to Elementor.

The language switcher works once Elementor is disabled which makes me think that the issue could also be linked to one of the Elementor Add-ons. Sadly, I can not debug the issue because as soon I disable one of these plugins the site shows a 500 error.

The 500 error on your site is kind of odd, as even if I disable all plugins and change the theme, the error persists.

Anyhow, now I was finally able to obtain a debug.log which shows me various errors from which some are related to WPML page builder compatibility classes.

In case you will run into another error please go to Dashboard -> Downloads and click the "Update" button at Theme and Plugins compatibility with WPML.

I would like to escalate the issue to our development team in order to review the errors and work on a solution. I will send you within some minutes a private message with instructions for migrating your website to our test server.

Kind regards
Andreas

December 6, 2019 at 10:51 pm #5086193

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

You will find the private information containing the server access credentials right above this message.

Make sure to leave me a short notification once the site is migrated.

Kind regards
Andreas

December 7, 2019 at 9:24 am #5086619

lucB-14

Hello Andreas,

Thanks for all the effort you put on this issue. Really appreciate.

The website is now migrated.

Kind regards

December 9, 2019 at 3:41 pm #5093977

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

Thank you for your patience.

I was sadly not able to find a solution for the issue but I realized that it occurs even if using the Twenty Twenty Theme and running the site only with WPML Multilingual CMS and Elementor PRO. The issue disappears when Elementor PRO is disabled, but I was not able to recreate the issue on a new install so far. Also, there have been not any errors found when debugging the site.

This is why I have sent the problem to our developer in order to investigate and I will be in contact once I received feedback.

Kind regards
Andreas

December 12, 2019 at 11:53 am #5114553

lucB-14

Hi Andreas,

Thanks for your help.
If Elementor Pro is the problem I cannot try anything by my side to fix the issue. I used Elementor Pro for the whole website.

So, I'm waiting for your reply.

Thanks a lot.
Luc

December 14, 2019 at 1:00 am #5126543

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

Our developers were able to find a fix for the issue and it will be implemented into the next updates for WPML.

Here our solution to apply directly on your site:

Go to: wp-content/plugins/sitepress-multilingual-cms/classes/display-as-translated/class-wpml-fix-links-in-display-as-translated-content.php

Between Line 29 and 39 try and replace the function with:

	public function fix_fallback_links( $content ) {
		global $post;
		if ( stripos( $content, '<a' ) !== false ) {
			$is_translated = apply_filters( 'wpml_element_has_translations', NULL, $post->ID, $post->post_type );
			if ( $this->is_display_as_translated_content_type() && ! $is_translated ) {
				list( $content, $encoded_ls_links ) = $this->encode_language_switcher_links( $content );
				$content = $this->translate_link_targets->convert_text( $content );
				$content = $this->decode_language_switcher_links( $content, $encoded_ls_links );
			}
		}

		return $content;
	}

Let me know if you need further assistance.

Kind regards
Andreas

December 17, 2019 at 8:55 am #5144507

lucB-14

Hi Andreas,

I replace the line as your advised but we coped with this message (Screenshot A) on our website.
When removing the '&' we got this other message (Screenshot B).

As a result, I cannot access the website at all.
Could you, please, a further look at it?

Thanks in advance.
Luc

Screen Shot A.png
Screen Shot B.png
December 17, 2019 at 2:44 pm #5148081

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

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

Hello,

I have replaced the fix inside of the respective WPML class file.

You are now able to access the site again.

Please reach out in case you experience further issues.

Kind regards
Andreas

December 18, 2019 at 10:59 am #5154445

lucB-14

Hello Andreas,
Yes! Now everything is working very well!

Thank you!