$site->url for multilanguage website

Sorry if this another noob question, but i want to add a custom menu item to my navbar.php.

If i use <?php echo $site->url() ?> this doesn’t work for both languages. I thought i needed $site->url([$lang=false]) to fix this but this gives me an error (llegal offset type in isset or empty)

This is my link:
Contact

What am i doing wrong?

Two options:

<?= $site->homepage()->url() ?>

or

<?= $site->url($site->language()->code()) ?>

Note that you are not supposed to use square brackets around $lang=false. $lang=false is the default value, you can optionally use a language code, e.g. $site->url('en') like in the second example above.

Why are there square brackets in the documentation, then? In this context, square brackets are used to indicate that a parameter is optional.

3 Likes