Echo $page->url() shows me always the same page on the entire site

Guys I really need your help. I’m stuck with a bug I can’t find!

Multilanguages site.
In my header snippet I have a div#languages with the following code:

<div id="languages">
    <?php foreach($kirby->languages() as $language): ?>
        <?php if($kirby->language() != $language): ?>
            <a href="<?php echo $page->url($language->code()) ?>" hreflang="<?php echo $page->url($language->code()) ?>">
                <?php echo html($language->code()) ?>
        <?php endif ?>
    <?php endforeach ?>

My website, though, always switches on the same page, both in Italian and German (not even the homepage) and I don’t understand why.

This is not the first time I use this code and it usually works just fine. That’s why I’m also thinking that maybe the problem is somewhere else.

If I print_r($page->uid()) or whatever in the header snippet always shows the same page, while if I do the same thing on a template the print is correct.

I use Kirby on this project.

Here my website on our dev server:

Do you have any idea? :pray:t2:

Thank you very much!

Have you redefined the $page variable in your header?

Unrelated to your issue, but the hreflang attribute may not contain a URL but the language and country code, e.g. de-DE.

I’m not a guy.

1 Like

Holy shit, how didn’t I see that?? Arghhh.
Thank you Sonja very much, also for the hreflang tip.

You’re not a guy (but guys is for everybody in the modern language :grin:) but you’re always the best!

1 Like

Hey Sonja! :wave:t2: :sweat_smile:

1 Like