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.

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

Problem: The domain part of the Yoast SEO canonical link is overwritten with the domain of the primary language. This is a non-existing URL on this site because only the domain gets overwritten. (note missing "rpa-")

Solution:
I would like to ask you to follow this steps:
- Edit the file classes/compatibility/wpseo/class-wpml-wpseo-filters.php in WPML, around line 72 we have to wrap the assignment with an if, like this:

// Only replace the URL if there is no canonical URL set by Yoast.
if ( '' === get_post_meta( $obj->ID, '_yoast_wpseo_canonical', true ) ) {
    $url = $this->canonicals->get_canonical_url( $url, $obj, '' );
}

Relevant Documentation:

This topic contains 11 replies, has 5 voices.

Last updated by David 1 month, 3 weeks ago.

Assigned support staff: Carlos Rojas.

Author Posts
July 30, 2018 at 11:49 am

Kwork Innovations

I am trying to:
Setup a cross-domain canonical link from a Post to the original source in another domain. I use Yoast SEO to setup the canonical link in antoher domain. I use WPML in domain per language mode.

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

I expected to see:

the full url present in Yoast SEO canonical link setting, including the domain
<link rel="canonical" href="hidden link" />
I see this result when I disable WPML.

Instead, I got:

The domain part of the Yoast SEO canonical link is overwritten with the domain of the primary language. This is a non-existing URL on this site because only the domain gets overwritten. (note missing "rpa-")
<link rel="canonical" href="hidden link" />

July 31, 2018 at 5:42 pm #2599436

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hello,
Thank you for contacting WPML support.

1.- I'm truly sorry but I don't understand the issue 🙁

Can you please elaborate a little more so I can better understand?

2.- Please increase the PHP Memory Limit. Minimum requirements are 128Mb: https://wpml.org/home/minimum-requirements/

You can add this to wp-config.php to increase WP memory:

/** Memory Limit */
define('WP_MEMORY_LIMIT', '128M');
define( 'WP_MAX_MEMORY_LIMIT', '128M' );

- Add it above the line /* That's all, stop editing! Happy blogging. */

Kind regards,
Carlos

July 31, 2018 at 7:26 pm #2599734

Kwork Innovations

Sorry for explaining badly. This has big importance for search engine optimization so I hope I can explain it properly.
----
Background and environment:
----
I use WPML. Each language has their own domain. Not all articles have been translated to every language, but articles have "translatable" enables in WPML settings.

I also use Yoast SEO plugin. For some articles I setup Canonical URL using this feature hidden link This feature adds <link rel="canonical" href=".."> tag in the source code of the article page. I call it the canonical tag. The href attribute points to the original source of the article, so search engine can now this is a copy of an article originally published elsewhere. This will avoid duplicate content penalties, among others.

----
Steps taken:
----
I add a new article on website hidden link with slug "rpa-robotic-process-automation" .
The URL of this is new article is now hidden link
It is also published on hidden link (secondary language)

The original article URL is hidden link which I set in Yoast SEO Canonical URL field.

----
I expect the source code of the page (right-click > View Source) to have this line
<link rel="canonical" href="hidden link" />

Instead, it has this line when WPML is enabled:
<link rel="canonical" href="hidden link" />

Page hidden link does not exist, because the slug is "rpa-robotic-process-automation"

----
It seems like Yoast SEO adds canonical tag correctly, but WPML replaces hidden link with hidden link (main domain of the site)

I think this problem is similar to https://wpml.org/forums/topic/yoast-canonical-domain-gets-overwritten-by-wpml/

However, I can not use the same solution, because I need to have the canonical tag set by WPML to point to the main domain in other articles.
For example hidden link needs to point to the main language hidden link as explained in this article https://wpml.org/2017/11/wpml-3-9-beta-makes-content-duplication-a-thing-of-the-past/

August 1, 2018 at 5:29 pm #2602899

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi,
Thank you very much for your feedback.

I just consulted the colleague who managed the ticket you mentioned (https://wpml.org/forums/topic/yoast-canonical-domain-gets-overwritten-by-wpml/) and the issue seems to be the same.

Just to confirm, does the solution provided here ( https://wpml.org/forums/topic/yoast-canonical-domain-gets-overwritten-by-wpml/#post-1534637 ) doesn't work for you?

In case the solution provided above doesn't work, I would like to ask you to follow this steps in order to isolate the cause of the issue:
- Back up your site first before making any change, this is for security reasons.
- Deactivate all the plugins that are not related to WPML.
- Switch for a moment to a WordPress default theme like Twenty Seventeen.
- If the issue is gone, activate one by one to see with which one there is an interaction issue.

Could you tell me the result of this steps?

Looking forward to your answer.
Best regards,
Carlos

August 1, 2018 at 7:08 pm #2603139

Kwork Innovations

The solution does not work, because then it does not add the canonical link to the primary domain for posts which have not been translated. I need it for posts which are available in the primary language and are visible on both domain. I also need updates for WPML for security reasons. (e.g. hidden link should have canonical link to hidden link because this is the content visible using this feature https://wpml.org/2017/11/wpml-3-9-beta-makes-content-duplication-a-thing-of-the-past/) .

Also, if I follow the proposed solution, I need to either disable WPML updates or I need to manually comment the line for each update. I need automated WPML updates for security reasons.

The issue is present when all other plugins are disabled and theme is Twenty Seventeen, except Yoast SEO and WPML are enabled. The issue seems to be with WPML compatibility with Yoast SEO.

1)
If Yoast SEO is disabled: I get canonical link to the primary domain on all posts and Yoast SEO's settings are ignored. This is not suitable, because I need canonical link to the original source.

2)
If I disable WPML: I get the correct canonical link for this post. I can not disable WPML because I need multilanguage feature.

3)
If I comment out the line as suggested in the other topic
//add_filter( 'wpseo_canonical', array( $this, 'canonical_filter' ) );:
I will not anymore get canonical tags to the primary domain for posts which have not been translated.

For example, url hidden link has canonical to hidden link instead of kwork.me (which it should be) after commenting out this line. This will cause duplicate content on separate URL's which will lead to SEO penalty.

August 1, 2018 at 8:09 pm #2603232

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi,

I dug deeper into this issue with one of our compatibility specialists and they are already working on a solution.

I will forward the details of this ticket and the Duplicator package to our compatibility team. I will get back to you as soon as I have an answer from them.

Thank you very much for your patience and understanding!
Best regards,
Carlos

August 1, 2018 at 10:38 pm #2603496

unimento

I have the same problem even, “domains and subdirectory”
Please is a big canonical issue.
Thanks in advanced.
Jose Manuel

August 6, 2018 at 2:08 pm #2616085

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi there,

I would like to ask you to follow this steps:
- Edit the file classes/compatibility/wpseo/class-wpml-wpseo-filters.php in WPML, around line 72 we have to wrap the assignment with an if, like this:

			// Only replace the URL if there is no canonical URL set by Yoast.
			if ( '' === get_post_meta( $obj->ID, '_yoast_wpseo_canonical', true ) ) {
				$url = $this->canonicals->get_canonical_url( $url, $obj, '' );
			}

This is what the whole function should look like when you are done (see attached image).

Could you confirm that the issue is solved?

Best regards,
Carlos

August 13, 2018 at 7:51 pm #2641092

Kwork Innovations

Hi,

Sorry for the delay.

Yes, this fixes the issue completely.

Is this expected to be part of WPML updates, or should I prepare methods to keep this change in my version?

Thank you for the efforts!

August 13, 2018 at 7:54 pm #2641095

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi there,

I'm glad to hear that the issue is solved 🙂

This fix should be added to future releases of the plugin.
Please don't hesitate to contact us if you need our help in the future with WPML. We will be more than happy to help.
Best regards,
Carlos

August 29, 2019 at 11:36 am #4480553

Alan

Meanewhile, has this added to the core WPML plugin?

August 29, 2019 at 11:48 am #4480583

David
Supporter

Languages: English (English ) Spanish (Español )

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

Yes, it was released in version 4.0.6
https://wpml.org/download/wpml-multilingual-cms/?section=changelog