Skip Navigation

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

Problem:
The client is using Elementor (Pro) with default widgets and is facing an issue where internal links have their titles translated but their href attributes are not updated to the translated page URLs. Instead, they point to the original URL. Some URLs are incorrectly pointing to a page ID instead of the proper URL.

Solution:
We recommend updating WPML and String Translation to the latest versions, as they include a fix for the mentioned problem. Please follow these steps:
1. Create a backup of your website or test on a staging version to avoid disrupting a live site.
2. Navigate to WordPress Dashboard > Plugins > Add New > Commercial (tab).
3. Click the "Check for Updates" button.
4. Update WPML and its addons.
For more information, please visit WPML's automated update documentation.

If this solution does not apply to your case, or if it is outdated, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket in the WPML support forum.

0% of people find this useful.

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 26 replies, has 4 voices.

Last updated by Christopher Amirian 10 months, 1 week ago.

Assisted by: Christopher Amirian.

Author Posts
November 30, 2023 at 12:35 pm #14962433

victorD-18

Hello Mateus,

Thank you for getting back to us. That's unfortunate. We had hoped that we can relay some sort of timeline to our client so we can manage there expectations.

We'll await the next update regarding the issue.

Best regards,
Codeslice

December 2, 2023 at 1:50 pm #14977669

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi Codeslice,

Thanks. we will inform if there is an update

February 26, 2024 at 1:33 pm #15344539

victorD-18

Hello Christopher,

We hope you are doing well. It's been 3 month's since we've last had contact and we've havent heard anything since.

It's been half a year since we've brought this issue to your attention and we want to know what's going on.

Thanks.

Codeslice

February 26, 2024 at 4:56 pm #15345575

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi Codeslice,

Unfortunately, there is no update at the moment that I can share, the issue is still in progress and no update is available.

Thank you for your understanding.

March 2, 2024 at 6:57 am #15365324

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

I double-checked and for now there is no fix other than this:

"unfortunately the only easy workaround that I can think of is editing the translation with the manual editor and selecting the translated item there."

There are a few low level changes needs to be done in the code to be able to tackle this issue and it will take time. I do not have ETA to share, but you can use the workaround above temporarily at the moment.

Thanks.

March 4, 2024 at 3:45 pm #15370808

victorD-18

Hi Christopher,

Thank you for double checking and the additional information regarding the issue. Now we have a better understanding of what's going on and why it's taking the amount time it already has.

Unfortunately manually editing will be a tedious and partial fix, since the client want's the whole website (78 pages) translated. Not forgetting having to rebuild the dynamic elements which refer to other pages, posts and elements. Those would have to be made static. In addition there are lot's of internal links mentioned in the content.

We still hope that the there will be a fix sooner then later. Low level changes or not, 6 months is a long time to wait for a solution. If possible, we'd be happy to learn what plugins and functionalities of those plugins are causing problems with WPML. Maybe we can rebuild those parts in order to find a temporarily workaround.

Finally, we appreciatie the ongoing communication and double checking on the issue. We've been using WPML for over 6+ years and based on our experience, it's the best multilingual solution for WordPress available. Since we have been receiving continuous support, updates and never had problems with WPML (up until 6 months ago), we hope this stays this way in the future want to show our appreciation and support with a donation. If you have a LINK or URL where we can donate, we'd be happy to do so.

Thank you.

Codeslice

March 11, 2024 at 4:50 pm #15396737

Nigel
Supporter

Timezone: Europe/Madrid (GMT+01:00)

Hi there

I'm Christopher's team manager, and he asked me to take a look at this to see if it could be prioritised.

There isn't any progress from the developers: they prioritise tasks based on several criteria, one of which is how many people are affected by an issue. I was surprised that there weren't more reports of this issue, given that it affects core Elementor functionality, and searching in the forum I did manage to dig up some other references to what appears to be the same problem.

So the first thing I've done is to communicate that on the internal ticket so that the developers see that more people are affected, and hopefully they will address it sooner.

But that may still take some time, so I also looked into the nuts and bolts of the problem to see if I could identify a workaround.

On my test site I have come up with some code that should make the links display correctly on translated pages, and you may want to test the same on your own site as an interim solution.

You should test thoroughly on a staging server first, though, before applying it to a production site.

Note that the eventual solution won't be the same and this code will become redundant, so we will leave this ticket escalated so that we can communicate when a solution is included in our plugins.

Here is the code for you to try that you can add to your child theme functions.php. Please let us know how you get on, so that we can share it with others as necessary.

/**
 * Filter the linked post in Elementor widgets that use internal-urls as Dynamic Links.
 */
add_filter( 'elementor/frontend/builder_content_data', 'wpmlsupp_filter_dynamic_elementor_internal_urls', 10, 2 );
function wpmlsupp_filter_dynamic_elementor_internal_urls( $data, $post_id ){

	$dynamic = locateElementByKey( $data, '__dynamic__');

	if ( $dynamic ) {
		
		// Does it have a link... 
		if ( isset( $dynamic['link'] ) ){
			$link = urldecode($dynamic['link']);

			// ...and is the link an internal-url?
			preg_match('/name="([^"]+)"/', $link, $nameMatches);
			if ( $nameMatches[1] == 'internal-url' ){
				
				// extract the settings containing the url
				preg_match('/settings="(.+?)\"\]$/', $link, $settingsMatches);
				if (!empty($settingsMatches[1])) {
				    $settingsJson = $settingsMatches[1];
				    $settings = json_decode($settingsJson, true);
					
					if ( isset( $settings['post_id'] ) ){
						$target_post = get_post( $settings['post_id'] );
						$translated = apply_filters( 'wpml_object_id', $target_post->ID, $target_post->post_type );
						if ( $translated != $target_post->ID ){
							// Update the settings with the ID of the translated post
							$settings['post_id'] = (string) $translated;
							// Replace the settings in the original string
							$updatedSettingsJson = json_encode($settings, JSON_UNESCAPED_SLASHES);
							$updatedSettingsJson = urlencode($updatedSettingsJson);
							// $updatedString = preg_replace('/settings="[^"]+"/', 'settings="' . $updatedSettingsJson . '"', $link);
							$updatedString = preg_replace('/(settings=")(.+?)(\"\]$)/', '${1}' . $updatedSettingsJson . '${3}', $link);
							$dynamic['link'] = $updatedString;
						}
					}
				}
			}			
		}
	}	
	return $data;
}

/**
 * Utility function to return a reference to an element of a multi-dimensional array
 * with the specified key, if it exists.
 */
function &locateElementByKey(&$array, $key) {
    $null = null; // Placeholder in case we don't find the key
    if (isset($array[$key])) {
        return $array[$key]; // Return a reference to the element if key is found
    }
    
    foreach ($array as &$element) {
        if (is_array($element)) {
            // Recursively search this element if it's an array
            $found = &locateElementByKey($element, $key);
            if ($found !== null) {
                return $found; // Return a reference to the found element
            }
        }
    }

    return $null; // Return null reference if the key is not found
}
March 14, 2024 at 1:42 pm #15410318

victorD-18

Hi Christopher and Nigel,

Thank you for the detailed response, elaboration on the issue and the internal proces. This is very much appreciated.

Thank you as well for the temporary fix/workaround. We'll make sure to test this in a staging/test environment before applying it to our production environment. When we do we'll share the results afterwards.

Best regards,

Codeslice

March 16, 2024 at 7:58 am #15416357

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Thank you very much.

April 4, 2024 at 9:08 am #15481770

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Would you please update WPML and String Translation to the latest version?

They contain a fix for the problem in question.

- IMPORTANT STEP! Create a backup of your website. Or better approach will be to test this on a copy/staging version of the website to avoid any disruption of a live website.
- Go to "WordPress Dashboard > Plugins > Add new > Commercial (tab)".
- Click the "Check for Updates" button.
- Update WPML and its addons there.

For more information:
https://wpml.org/faq/install-wpml/#automated-updates

Thank you.

April 4, 2024 at 12:31 pm #15483061

victorD-18

Hi Christopher,

Thank you for the promising update. We'll make sure to update WPML and all accompanying plugins to there most recent version.

When we do, we'll get back here to share the results.

April 6, 2024 at 7:03 am #15490252

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Sure. Thank you.

April 7, 2024 at 11:47 am #15491554

victorD-18

Dear Chrisopther, Nigel and the rest of the team at WPML,

We've applied the update in a staging/test envoirement and after some testing it seems that the Elementor mega-menu and the mentioned internal links are properly being translated. We've noticed that deleting the old translations and re-creating them was more effective then trying to apply changes to the already existing translations in order to change the URL's to the right language.

We're happy to share the news with our client!

Again, many thanks for the great support!

Best regards,
Codeslice