Disable Pages in Hugo Website Disable Pages in Hugo Website

Page content

In this tutorial, we’ll learn how to disable different kind of pages in Hugo website such as home, section, taxonomy, term, sitemap.xml, RSS feeds, robots.txt and 404 error pages.

Overview

When you generate a website using Hugo static site generator. Hugo auto generates different kind of pages for you which are generally required for a website.

Refer this table for kind of pages Hugo support:

Kind Description Example
home Home page of your website /
section Section pages, which list all the pages rendered from a subdirectory in our content folder. /posts
page Individual blog post pages /posts/my-post/
taxonomy Taxonomy e.g. Tags pages, which list all the tags of the website. /tags
term Term pages e.g. “trending” tag, which list all the pages using this particular tag /tags/trending
RSS RSS Feeds index.xml
sitemap Sitemap of your website used for indexing pages of you website by search engines sitemap.xml
404 404 error page used when any URL not found in your website /unknownurl

All these kind of pages are good to have for your website but sometime they are not required for a basic website.

Disable Pages

Good news is that you can disable any kind of page from the configuration using disableKinds which takes comma separated values. Possible values are: “page”, “home”, “section”, “taxonomy”, “term”, “RSS”, “sitemap”, “robotsTXT”, “404”.

Disable Pages using config.toml

This approach is recommended, when you want to disable pages permanently everytime you build your website.

Let’s disable all the auto generated pages permanently by giving comma separated values in disableKinds configuration.

config.toml
title = "Hugo example site"
baseurl = "https://www.example.com"

disableKinds = ["page", "home", "section", "taxonomy", "term", "RSS", "sitemap", "robotsTXT", "404"]

[taxonomies]
    category = "categories"
    tag = "tags"

You can also prevent a specific page from generation by Hugo as follows:

  • RSS Feed Hugo auto generate RSS Feed using built-in RSS 2.0 template for whole website, for each section, for each taxonomy term and for each taxonomy value pages. We can turn off the RSS Feed for all these pages as follows:

    config.toml
    disableKinds = ["RSS"]
  • sitemap.xml Hugo auto generate sitemap.xml using built-in Sitemap Protocol v0.9 template for whole website. We can prevent sitemap.xml from generation as follows:

    config.toml
    disableKinds = ["sitemap"]
  • robots.txt Hugo auto generate robots.txt for your website. We can turn off the robots.txt generation as follows:

    config.toml
    disableKinds = ["robotsTXT"]

    Alternatively we can turn off the enableRobotsTXT flag in config file

    config.toml
    enableRobotsTXT = false
  • 404.html Hugo auto generate 404.html for your website. We can turn off the 404.html generation as follows:

    config.toml
    disableKinds = ["404"]

    Alternatively we can delete or rename 404.html file from /layouts/404.html location to turn it off.


Disable Pages using command-line

This approach is recommended, when you want to disable pages at runtime for a specific build of your website.

Let’s see how we can disable all the auto generated pages in current build by executing the command from terminal:

hugo --disableKinds=page,home,section,taxonomy,term,RSS,sitemap,robotsTXT,404