Custom title tag on the homepage

This is in my header.php snippet.

<title><?php echo $site->title()->html() ?> | <?php echo $page->title()->html() ?></title>

I want every page except the homepage to show the code above, but on the homepage I want to use a custom title after the | while retaining the title of the homepage (which is “Home”).

I know I could probably just use a different snippet for the homepage, but if possible I’d like to simplify it to just one snippet and I can’t seem to figure it out.

Just check if it’s the homepage in your snippet and depending on this you either add $page->title() or your custom thing (e.g. stored as a $site field) after the |.

  <?php if($page->isHomepage()): ?>
<title><?php echo $site->title()->html(); ?> | <?php echo $site->customthingy()->html(); ?></title>
<?php else: ?>
<title><?php echo $site->title()->html(); ?> | <?php echo $page->title()->html(); ?></title>
<?php endif ?>
4 Likes

Wow that was quick. Thanks a lot. :smile: