How to Exclude Specific Posts from Hugo RSS Feeds

Learn how to selectively exclude content from your Hugo site's RSS feed while keeping it visible on your website

When managing a Hugo static site, you might encounter situations where you want certain posts to appear on your website but not in your RSS feed. Perhaps you’re publishing internal announcements, draft previews, or content that’s only relevant to direct website visitors. Hugo doesn’t provide this functionality out of the box, but with a simple modification to your RSS template, you can gain granular control over what appears in your feed.

The Challenge

By default, Hugo includes all published posts in your RSS feed. While you can use the draft: true parameter to exclude content entirely, this removes the post from both your site and RSS feed. What if you want more nuanced control?

The Solution: Custom RSS Filtering

The solution involves modifying your RSS template to filter out posts based on custom front matter parameters. Here’s how to implement it:

Step 1: Modify Your RSS Template

First, locate your RSS template file. This is typically found at layouts/_default/rss.xml in your Hugo site. If you don’t have a custom RSS template, you can create one by copying Hugo’s default RSS template.

Add filtering logic to exclude posts with specific parameters:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = $pctx.RegularPages -}}
{{- else -}}
{{- $pages = $pctx.Pages -}}
{{- end -}}
{{- $pages := where $pages "Params.hidden" "!=" true -}}
{{- $pages = where $pages "Params.exclude_from_rss" "!=" true -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}

The key lines are:

  • {{- $pages := where $pages "Params.hidden" "!=" true -}} - Excludes posts with hidden: true
  • {{- $pages = where $pages "Params.exclude_from_rss" "!=" true -}} - Excludes posts with exclude_from_rss: true

Step 2: Using the Exclusion Parameters

Now you have two ways to control RSS inclusion:

Option 1: Complete Hiding

Add to your post’s front matter to hide from both site and RSS:

1
2
3
4
5
---
title: "My Private Post"
date: 2025-08-31
hidden: true
---

Option 2: RSS-Specific Exclusion

Add to your post’s front matter to exclude only from RSS:

1
2
3
4
5
6
7
---
title: "Website-Only Announcement"
date: 2025-08-31
exclude_from_rss: true
categories:
    - Announcements
---

Real-World Use Cases

This functionality is particularly useful for:

  • Internal announcements - Company updates that don’t need to reach external RSS subscribers
  • Draft previews - Sharing work-in-progress content with select audiences
  • Seasonal content - Holiday messages or temporary notices
  • Meta content - About pages, privacy policies, or site maintenance notices
  • Testing content - Posts used for design or functionality testing

Complete RSS Template Example

Here’s a complete, minimal RSS template with the filtering logic:

File Path: layouts\_default\rss.xml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = $pctx.RegularPages -}}
{{- else -}}
{{- $pages = $pctx.Pages -}}
{{- end -}}
{{- $pages := where $pages "Params.hidden" "!=" true -}}
{{- $pages = where $pages "Params.exclude_from_rss" "!=" true -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
        <link>{{ .Permalink }}</link>
        <description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
        <generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
        <language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
        <managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
        <webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
        <copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
        <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
        {{- with .OutputFormats.Get "RSS" -}}
        {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
        {{- end -}}
        {{ range $pages }}
        <item>
            <title>{{ .Title }}</title>
            <link>{{ .Permalink }}</link>
            <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
            {{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
            <guid>{{ .Permalink }}</guid>
            <description>{{ .Summary | html }}</description>
        </item>
        {{ end }}
    </channel>
</rss>

Testing Your Implementation

After implementing the changes:

  1. Build your site: Run hugo to generate the static files
  2. Check the RSS feed: Look at yourblogonthecloud/rss.xml to verify excluded posts aren’t present
  3. Validate the XML: Ensure the RSS feed is still valid XML
  4. Test with RSS readers: Verify the feed works correctly with RSS readers

Alternative Approaches

While front matter filtering is the most flexible approach, you could also:

  • Use sections: Create a separate content section for RSS-excluded content
  • Use taxonomies: Filter based on specific categories or tags
  • Use build conditions: Conditionally include content based on build parameters

Conclusion

With this simple modification to your Hugo RSS template, you gain fine-grained control over what content appears in your RSS feed. This flexibility allows you to serve different audiences appropriately - keeping your website comprehensive while maintaining a focused, relevant RSS feed for subscribers.

The beauty of this approach is its simplicity and non-intrusive nature. Existing posts remain unaffected, and you only need to add exclusion parameters when you specifically want to control RSS visibility.

Share with your network!

Built with Hugo - Theme Stack designed by Jimmy