Skip to content

Kirby 3.9.8

Custom homepage title

Let's see how we can set an HTML title tag with Kirby.
You can use the site wide $site->title() in connection with the title of the current page $page->title to generate something pretty decent:

<title><?= $site->title() . ' – ' . $page->title() ?></title>

…or…

<title><?= $page->title() . ' | ' . $site->title() ?></title>

…just however you prefer.

But what if you want to have a very descriptive title for your homepage or just the site title, without adding an extra template for it?

Kirby has the built-in $page->isHomePage() function, which makes it fairly simple to change your title only on the homepage:

<?php if ($page->isHomePage()): ?>
<title>Welcome to my fantastic, awesome, little website</title>
<?php else: ?>
<title><?= $site->title() . ' – ' . $page->title() ?></title>
<?php endif ?>

…or maybe just…

<?php if ($page->isHomePage()): ?>
<title><?= $site->title() ?></title>
<?php else: ?>
<title><?= $site->title() . ' – ' . $page->title() ?></title>
<?php endif ?>