Editable redirects with target: _blank


First of all: I’m still a newbie. So forgive maybe dumb questions.

I’ve set up a editable redirect, which works fine. But I want the link to open in a new tab (target: _blank) and thought, I’ve to add something to the link.php (see code-block) in my templates-folder. But nothing I’ve tried, worked.

<?php go($page->link(), 301) ?>

My research in the docs found nothing obvious. I’ve looked maybe on the wrong spots: page-objects, go-helper

If there is a solution to my problem it would be nice. Please point me to the right docs, if there is documentation, I’ve missed.

Thank you!


The target="_blank" attribute needs to be provided in the <a href=""> element in your template – for example: <a href="/redirectedurl" target="_blank">Click here to be redirected (opens in a new window)</a>.

The go() helper triggers a HTTP-redirect response, which redirects the browser to load a different URL than initially requested, but it will only be loaded into the existing context in the browser (hence opening the new target has to happen already in the <a> element).

If I got it right:
Opening a new tab is not an option, because there is nothing to click on? I can’t add target: _blank to that PHP?

(Newbie-Warning :woozy_face:)

No worries, I’m happy to elaborate :slight_smile:

Your understanding is correct. It is never possible to open a new tab by means of a HTTP Redirect response (so this is not a Kirby limitation). If somebody calls the URL example.com/redirectmeplease, Kirby cannot force their browser to redirect to the URL example.com/target and tell the browser to open that in a new window. HTTP Redirects (which is what the go() helper sends back to the browser) do not have the “power” to control a browser’s window management.

What can be done is to embed a link in your website – say, in your footer – that links to
example.com/redirectmeplease, open that link in a new window and then have that window redirected to display the page at example.com/target. To achieve this, use the target="_blank" attribute in the <a> element, as presented in my earlier reply.

In other words: you can only control to open new windows in the context where the user clicks on a link, not on the server side where you carry out a redirect.

Thank you!
That clarification helps a lot. :slight_smile:

I’ve thought, Kirby has “the force” or something like that to help me… :grin: