Setting Noindex for Hugo Taxonomy Pages

Setting Noindex for Hugo Taxonomy Pages
Figure: https://learn.netlify.com/en/shortcodes/attachments/

Taxonomies in Hugo are a great way to structure information provided by a blog. For search engine optimization (SEO) purposes, however, the existence of duplicate content on a site can be a problem. If you think this is the case for your site, then you can use the noindex meta tag for all of the taxonomy sites that do not provide unique content. This post shows you how to get it done.

Adjust your theme’s baseof.html file

The file baseof.html defines the basic structure of your website. You can find it under layouts/_default of your theme’s folder. For example, my baseof.html is located under themes/Mainroad/layouts/_default/baseof.htm. Simply add this code within the head tag:

{{ if .Data.Singular }}
    <meta name="robots" content="noindex">
{{ end }}

This should instruct all indexers not to index the taxonomy pages. To make sure that it worked you can contrast the HTML meta tags that are generated for regular posts and taxonomy pages.

Why does it work?

According to the taxonomy variable documentation, there are some special variables that are only available for taxomy pages. I’ve just picked one of the taxonomy variables (i.e. .Data.Singular) but I could also have used any of the other taxonomy variables (e.g. .Data.Terms). By requiring the existence of these variables, the noindex tag is only set for the taxonomy pages.

Keeping noindex and the sitemap concordant

If you are setting a site to noindex it also makes sense to remove it from the sitemap. To do this, you can customize the default Hugo template template by including the same if-condition as for the noindex tag.

Is noindex really the way to go?

While noindex is viable in some situations, I’m currently not using noindex for the taxonmy pages on this blog because they are attracting a lot of search traffic. You should think about the taxonomy pages as landing pages to your blog. So, it makes sense to improve upon the most important taxonomy pages rather than blocking them.

Author: Matthias Döring