multiple-domain icon indicating copy to clipboard operation
multiple-domain copied to clipboard

Canonical and hreflang tag issues

Open straube opened this issue 5 years ago • 2 comments

Issues reported on the plugin support forum (https://wordpress.org/support/topic/two-problems-25/):

  1. 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.

  2. Plugin is adding hreflang=”x-default even when my language settings is None.

straube avatar Jan 16 '20 16:01 straube

Thanks for your concern.

thegulshankumar avatar Jan 16 '20 18:01 thegulshankumar

@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

thegulshankumar avatar Jun 03 '20 04:06 thegulshankumar