Overwrite Default RSS Feed in Hugo

This post will be very short and precise. In Jekyll, we had to create an .xml file using liquid templates to tell Jekyll that we want an rss.xml or similarly sitemap.xml. Luckily, Hugo creates these files for us under the hood. You can check them by going to /index.xml and /sitemap.xml pages in your Hugo website. Hugo even creates “index.xml” for sections and taxonomies.

However, you may want to overwrite the default RSS template because it’ll include only the pages directly under your root (/content) folder and it’ll include pages like about.md. To overwrite the default RSS template, you need to copy the original template into /layouts/_default/and name it as index.rss.xml.

Then you need to, change how it loops over {{ range $pages }}. This is how I set $pages to include all sub-folders (sections as Hugo called them) and exclude ordinary pages like “about page”.

{{- $pages := where $.Site.RegularPages ".Type" "!=" "ordinary" -}}

Done!

One last thing, if you name the file as /layouts/_default/rss.xml, then it will affect all RSS files including section RSS, taxonomy RSS. For example, let’s say I have a section called “blog” then Hugo will generate an RSS feed at /blog/index.xml. This is the default behavior. If we name the file as rss.xml instead of index.rss.xml Hugo will apply our template not only on /index.xml but also /blog/index.xml which is not what I want. See, RSS Template Lookup Order from Hugo docs.

Next Episode

published on 06.08.2020

Search engine bots or crawlers, use two files to crawl a website more intelligently. These are robots.txt and sitemap.xml. A robots.txt file tells search engine crawlers which pages or files the crawler can or can’t request from the site. This is used mainly to avoid overloading your site with …

Previous Episode

published on 21.08.2020

“Overwriting default landing page for Hugo taxonomies”. What do I mean by that? By default, Hugo will create a home page or a landing page for your taxonomies. /tags/ or /categories are good examples. If you don’t have any specific templates for tags /layouts/tags/list.html Hugo …

TAG CLOUD