Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Hreflang x-default tag not appearing

  • 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?

  • You think Polylang may be blocking the hook?

    I’ll try them.

    Thanks Leo

  • Mmmmmm, Polylang only answer questions on their Pro model, which is pricy.
    I guess I’ll keep searching.

  • 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?

  • Yes, thanks, Alvind. This snippet works a dream.

    Thank you guys as always for your prompt reactions!

  • You’re welcome, glad to hear that!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.