Only Show HTML When on Local/Production

For Hugo Themes, you will sometimes want to act differently between you working on the site, developing it, and the site if it’s running publicly on the internet. One example of this is if you show advertisements - you don’t want them showing on local (and contributing to impressions) but you would want to show them to the world.

The reverse is also true, you could load scripts like livereload only on local development, through hugo server.

This post shows how to do both scenarios below.

Production Only

1
2
3
{{ if not .Site.IsServer }}
    <!-- production only -->
{{ end }}

Local Only

1
2
3
{{ if .Site.IsServer }}
    <!-- local development -->
{{ end }}