-
Johndavidhalifax
Hi there.
I am using GP premium 2.5.0 on WP 6.6.2
I hope you can help with this:I have a multilingual site, using Polylang.
I first set Polylang to show the language extension (/en/) for the default language. Polylang made nice hreflang tags in the header: one for each language plus <link rel=”alternate” hreflang=”x-default” href=”https://sitename.com/en/” />.But with a homepage extension /en/home-page, I had trouble with the canonical version. So I set Polylang to “Hide URL language information for default language “. Great, a root home page address, no canonical conflict.
But while Polylang still sets the hreflang for each language, it no longer sets the hreflang x-default. So I made a wp_head hook to display the x-default tag on the front page and the other language home pages.
But this hook doesn’t work, nothing is shown in the page head.
Do you have an idea why?
-
Hi there,
I don’t believe this is theme-related and unfamiliar with Polylang.
Have you tried contacting Polylang’s support team?
-
Johndavidhalifax
You think Polylang may be blocking the hook?
I’ll try them.
Thanks Leo
-
Johndavidhalifax
Mmmmmm, Polylang only answer questions on their Pro model, which is pricy.
I guess I’ll keep searching. -
Johndavidhalifax
Wow, I finally found something that works! Just in case you are interested:
Put this snippet:
add_filter( ‘pll_rel_hreflang_attributes’, function( $hreflangs ) {
$hreflangs[‘x-default’] = $hreflangs[‘en’];
return $hreflangs;
} );It adds hreflang x-default to all pages, cool.
-
Hi there,
Just to confirm, have you managed to resolve this?
-
Johndavidhalifax
Yes, thanks, Alvind. This snippet works a dream.
Thank you guys as always for your prompt reactions!
-
You’re welcome, glad to hear that!
- You must be logged in to reply to this topic.