Buttons and links

I have troubles with adding links via panel. I use this approach to create buttons with url link and link text (see below) which I can edit via panel, but the problem is that even though I add different url link via panel it still shows the path to the current (active) page and it doesn’t redirect to proper page after clicking on button. Could someone explain me how it should be done in a correct way?

<a href="<?= $page->url()?>" class="button" role="button"><?= $page->linktext()->html() ?></a>

Thanks! Sorry if it’s a stupid question, but I still struggle a bit with PHP and Kirby.

Is your field for the page you want the link to called url? If so url is a page method that will always get the link of the page you call it on.

You would have two options:

1. Rename your field from url to link or something similar and use it like this:

<a href="<?= $page->link()?>" class="button" role="button"><?= $page->linktext()->html() ?></a>

2. Get the content field via $page->content()->url().

<a href="<?= $page->content->url()?>" class="button" role="button"><?= $page->linktext()->html() ?></a>

Thanks for help! The first solution was what I was looking for.