From 65cd983ba60dc881d193b454a0d20afb57be9d05 Mon Sep 17 00:00:00 2001 From: HerrVigg Date: Sun, 31 May 2020 14:03:12 +0200 Subject: [PATCH] Fix hreflang default URL no browser detect (#198, #819) Only if the language is detected by the browser, enforce the language shown to make the default URL deterministic for SEO. Otherwise, allow the option "Hide URL language information for default language". Note the "x-default" item is not concerned by these changes, this link always uses the default URL with no override. --- qtranslate_frontend.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qtranslate_frontend.php b/qtranslate_frontend.php index d5cff9e7..e0a1e825 100644 --- a/qtranslate_frontend.php +++ b/qtranslate_frontend.php @@ -40,14 +40,18 @@ function qtranxf_wp_head() { return; } - // set links to localized versions of current page: hreflang (locale/lang) -> href + // Set links to localized versions of the current page using for SEO (hreflang) + // See https://github.com/qtranslate/qtranslate-xt/wiki/Browser-redirection#localized-versions-for-seo-hreflang $hreflangs = array(); foreach ( $q_config['enabled_languages'] as $lang ) { $hreflang = ! empty ( $q_config['locale_html'][ $lang ] ) ? $q_config['locale_html'][ $lang ] : $lang; - // Default language is always shown, see: https://github.com/qtranslate/qtranslate-xt/wiki/Browser-redirection - $hreflangs[ $hreflang ] = qtranxf_convertURL( '', $lang, false, true ); + + // The default URL may be deterministic or not, depending on the option for language detection by the browser + // If language detected, enforce default language shown to make the default URL deterministic for SEO + // Otherwise, allow option "Hide URL language information for default language" + $hreflangs[ $hreflang ] = qtranxf_convertURL( '', $lang, false, $q_config['detect_browser_language'] ); } - // Fallback for unmatched language: https://support.google.com/webmasters/answer/189077 + // Fallback for unmatched language (default hreflang for SEO) $hreflangs['x-default'] = qtranxf_convertURL( '', $q_config['default_language'] ); $hreflangs = apply_filters( 'qtranslate_hreflang', $hreflangs );