Conditional language link in menu

I have a one-page site that uses anchor links for navigation, with a menu snippet that is used in both the Dutch and English version. The Dutch website is just, whereas the English version is at So the anchor links are and My question is: how can I set up the menu links to behave properly in this setup?

What I tried was this, but it doesn’t work:

<a class="menu-link" href="<?php if ( e($language->default() ) { echo $site->language() } ?>/#<?php echo $p->title() ?>"><?php echo $p->title()->html() ?></a>

Just leave out that conditional thingy and it should work without any problems:

<a class="menu-link" href="#<?php echo $p->title() ?>"><?php echo $p->title()->html() ?></a>

Ah, sorry, I should have added: it does work fine without the conditional, but the point is that the link should be either just the #anchor-link, or en/#anchor-link. Hence the if-statement.

But if you add “en/#anchor” to, you will end up on the error page …, so where’s the point? Nevertheless, the syntax to achieve that would be:

<a class="menu-link" href="<?php e($site->language()->default(), '#', 'en/#'); echo $p->title() ?>"><?php echo $p->title()->html() ?></a>

Ah, well that’s my mistake, then. What would be the correct way to point to an anchor link in a multilingual website like this?

If it helps, the URL is

But that works perfectly alright and I don’t see why that should be any different, sorry. Maybe I just don’t understand what exactly it is that you want to achieve … but I don’t see any need for any language specific implementation or what that should be.

Haha, I suppose I haven’t been clear enough, sorry. works, and the anchor links there work, but say you’re on the English-language error page. There, the anchor links in the menu won’t work. So ideally I would like to re-do the anchor links so that they would work everywhere. So I thought I could just add /en/ in front of them if the current language is English.

Now I’m with you, but that’s a problem that is not language specific but you’ll have that on every one pager with additional pages … Anyway, the url() helper is your friend :smile:

<a href="<?php echo url();e($site->language()->default(), '/#', '/en/#'); echo $p->title ?>"> ...</a>

Ah yes, thank you so much!

Just one small note, I think it’s echo $p->title() in the last echo statement you put. But, again, thank you very much!

Oh, yes, I forgot to add the parenthesis when I changed from my test code to your’s … I’ll correct it above.