"> ">

Control site indexing in Hugo with <meta name="robots">

Learn how to use a front matter setting to control site indexing via meta robots tags.

This article is part of the series "SEO Basics: Indexing."

TL;DR

  • introduce a new setting to your front-matter “index”
    • when set to true, the page should be indexed
  • use it in head template at layouts/partials/head/head.html to generate the according meta robots tag
{{- if .Params.index }}
<meta name = "robots" content = "index">
{{- else }}
<meta name = "robots" content = "noindex">
{{- end }}
  • if you are using a theme, copy their head.html and adjust it accordingly. Hugo will use your template when building for prod but a head.html partial usually contains more than just the meta robots tag

Warning

Keep in mind: This will lead to all content not being indexed and only content being indexed where you specify “index = true” in your front matter. This also means that content automatically generated by Hugo (i.e. content you do not manually curate a template for) will not be indexed.

Further reading

“Robots” - Control what is indexed

Built with Hugo
Theme Stack designed by Jimmy