Make Site Logo Link Dynamic

Partials are a great way to break down static sites into small components. But some components need to ce different on different pages, E.G, the link leading to site homepage should not appear on the home page itself. Fortunately, we can use Hugo’s extensive variable and conditionals support:

{{ if .IsHome }}
    <h4>Postscriptum</h4>
{{ else }}
    <h4><a href="{{ .Site.BaseURL }}">Postscriptum</a></h4>
{{ end }}

First we check the page variable .IsHome. If it is true, the logo is simple text, <h4>Postscriptum</h4>.
If not, we are not at the home page and need a link:
<h4><a href="{{ .Site.BaseURL }}">Postscriptum</a></h4>
Here we use a global variable {{ .Site.BaseURL }} from site’s config.toml file to substitute it with the homepage URL.

May 29, 2021   (v.93940b5)