1 min read
Show the full page hierarchy in the HTML title tag with Kirby
Kirby provides a built in breadcrumb()
function and a handy example to show users their current journey within a site. The order need to be reversed for the browser title so the current page title is listed first so it’s visible to the user.
<?php | |
// Start off with an empty $title | |
$title = ''; | |
// Get all the parents (except the homepage) and reverse the array | |
$parents = $site->breadcrumb()->not('home')->flip(); | |
// Iterate over the array | |
foreach ($parents AS $parent) : | |
// Add each title to a variable (with a pike as a separator) | |
$title .= $parent->title() . ' | '; | |
endforeach; | |
// Add the site title last | |
$title .= $site->title(); | |
?> | |
<!-- Echo the title variable inside the <title> tag --> | |
<title><?php echo $title; ?></title> |