multiple-domain
multiple-domain copied to clipboard
Canonical and hreflang tag issues
Issues reported on the plugin support forum (https://wordpress.org/support/topic/two-problems-25/):
Plugin is adding wrong canonical link that is missing Trailing slash in post permalink at the end. – Yoast already take care of this part. And, I could fix this by disabling “Add canonical link” checkbox.
Plugin is adding hreflang=”x-default even when my language settings is None.
Thanks for your concern.
@straube Hi
Bug: Wrong x-default
Suppose, English is the primary language. Spanish version is added via WPML.
<link rel="alternate" hreflang="en" href="https://example.com/about/" />
<link rel="alternate" hreflang="es" href="https://example.com/es/acerca-de/" />
Problem
If I go to view-source:https://example.com/es/acerca-de/
when plugin active it print in head
<link rel="alternate" href="https://example.com/acerca-de/" hreflang="x-default" />
Expected
<link rel="alternate" href="https://example.com/about/" hreflang="x-default" />
Well, I am already able to add proper x-default tag with below snippet
/* ---------------------------------------------------------------------------
* Set hreflang="x-default" with WPML
* --------------------------------------------------------------------------- */
add_filter('wpml_alternate_hreflang', 'wps_head_hreflang_xdefault', 10, 2);
function wps_head_hreflang_xdefault($url, $lang_code) {
if($lang_code == apply_filters('wpml_default_language', NULL )) {
echo '<link rel="alternate" href="' . $url . '" hreflang="x-default" />'.PHP_EOL;
}
return $url;
}
Please make adding hreflang optional and fix it as well.
Thanks