# Link to RSS feed on all pages using OutputFormats

**URL:** https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598
**Category:** support
**Created:** [April 18, 2018, 4:20pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598 "2018-04-18T16:20:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Grob](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@Grob](https://discourse.gohugo.io/u/Grob)
#### Post date: [April 18, 2018, 4:20pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/1 "2018-04-18T16:20:03Z")

</div>

Hi all!

How is it possible to link to `/index.xml` (feed url may be changed) on _all_ pages using [this technique](https://gohugo.io/templates/rss/#the-embedded-rss-xml).

Currently the feed is linked on the landing page only. It would make sense to include the ”basic feed“ on all pages—maybe also section feeds.

Of course, you can just type out `<link …>`. Yet, I would like to automate it for re-usable templates and changed output formats for the RSS feed.

Thank you very much!

---

<div class="post-metadata">

### Author: ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)
#### Post date: [April 18, 2018, 4:35pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/2 "2018-04-18T16:35:40Z")

</div>

> [@Grob](#):
>
> How is it possible to link to /index.xml (feed url may be changed) on all pages

The RSS alternate output is enabled by default for home, section, taxonomy and taxnomyTerm pages (See [Page Kinds](https://gohugo.io/templates/section-templates/#page-kinds)).

So you simply need to add a code like this in your `baseof.html` (See [Base Templates and Blocks](https://gohugo.io/templates/base/)):

```auto
{{ range .AlternativeOutputFormats -}}
    {{ printf "<link rel=\"%s\" type=\"%s+%s\" href=\"%s\" title=\"%s\" />" .Rel .MediaType.Type .MediaType.Suffix .Permalink (printf "%s for %s" (.Name | title) $.Site.Title) | safeHTML }}
{{ end -}}

```

Above is a slightly improved version of the snippet in [docs](https://gohugo.io/templates/rss/#reference-your-rss-feed-in-head).

---

<div class="post-metadata">

### Author: ![Grob](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@Grob](https://discourse.gohugo.io/u/Grob)
#### Post date: [April 18, 2018, 6:58pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/3 "2018-04-18T18:58:50Z")

</div>

Thanks a lot, kaushalmodi.

/index.xml still only shows up on the homepage.

On pages no alternate link is shown (unless you set `page = ["HTML", "RSS"]`); section pages link to the section feed, but not to the base feed.

Any other idea (or am I doing something wrong?)?

---

<div class="post-metadata">

### Author: ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)
#### Post date: [April 18, 2018, 7:00pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/4 "2018-04-18T19:00:53Z")

</div>

> [@Grob](#):
>
> On pages no alternate link is shown (unless you set page = [“HTML”, “RSS”]);

Correct. That is expected.

Note that I did not have “page” in the list I wrote earlier:

> The RSS alternate output is enabled by default for home, section, taxonomy and taxnomyTerm pages

See [Default Output Formats](http://gohugo.io/templates/output-formats/#default-output-formats).

---

<div class="post-metadata">

### Author: ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)
#### Post date: [April 18, 2018, 7:02pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/5 "2018-04-18T19:02:25Z")

</div>

> [@Grob](#):
>
> section pages link to the section feed, but not to the base feed.

That is expected too… So you need the section pages to link to the feed in home page too? Then why generate the section feeds?

If you need to hard-code all pages to link to the home page feed, you need to hard-code that link in the templates.

---

<div class="post-metadata">

### Author: ![Grob](https://avatars.discourse-cdn.com/v4/letter/g/f14d63/32.png) [@Grob](https://discourse.gohugo.io/u/Grob)
#### Post date: [April 18, 2018, 7:42pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/6 "2018-04-18T19:42:58Z")

</div>

Yes, that is correct. Actually everything works properly and as expected. I was just wondering if it was possible to have a link to /index.xml on all pages using `range .OutputFormats`. It is also responsivble for non hard coded canonical output. It would have been nice and out of the box to use it for feed and canonical link in all my templates.

Hard coding is no problem, of course.

Thanks a lot!

---

<div class="post-metadata">

### Author: ![mdavidmorton](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mdavidmorton/32/10105_2.png) [@mdavidmorton](https://discourse.gohugo.io/u/mdavidmorton)
#### Post date: [December 5, 2019, 7:48pm UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/7 "2019-12-05T19:48:38Z")

</div>

I came here trying to do the same thing (I think). I only have 2 feeds enabled for the whole site — RSS and JSON. Both are enabled for just the homepage. I want them in the head of every page, but I don’t want to hard code them. Here’s what I came up with:

```auto
{{- with .Site.GetPage "/" }}
    {{- range .OutputFormats }}
        {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
    {{- end }}
{{- end }}

```

---

<div class="post-metadata">

### Author: ![idarek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/idarek/32/26229_2.png) [@idarek](https://discourse.gohugo.io/u/idarek)
#### Post date: [January 29, 2023, 8:57am UTC](https://discourse.gohugo.io/t/link-to-rss-feed-on-all-pages-using-outputformats/11598/8 "2023-01-29T08:57:34Z")

</div>

It may be old post but still valid.

I recently noticed that on single pages (posts) there is no reference to the main RSS feed (which I want to add) and on category pages or tags pages the title for the RSS feed is exactly as the main feed (which may be confusing and I want to change it).

> For example  
> for `/index.xml` the RSS title will have the same property as if `/categories/blog/index.xml`, so decided to change it and come up with the following (in case somebody will need it).

```auto
  {{ with .OutputFormats.Get "rss" -}}
    {{ if eq (absLangURL "") $.Permalink }}
      {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
    {{ else }}
      {{ $title := (printf "%s (%s)" $.Site.Title $.Title) }}
      {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $title | safeHTML }}
    {{ end }}
  {{ end -}}

  {{ if ne (absLangURL "") $.Permalink }}
    {{- with .Site.GetPage "/" }}
      {{- with .OutputFormats.Get "rss" }}
          {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
      {{- end }}
    {{- end }}
  {{ end }}

```

Works in a multilanguage environment.

* * *

In reference to:

> **[ทำให้เนื้อหาปรากฏใน Discover | Google Search Central  | ...](https://developers.google.com/search/docs/appearance/google-discover?hl=th)**
>
> ฟีด Discover ของ Google แสดงเนื้อหาเกี่ยวกับสิ่งที่ผู้ใช้สนใจ เอกสารประกอบนี้จะให้ความรู้เกี่ยวกับวิธีทำให้เนื้อหาของคุณปรากฏใน Discover รวมถึงวิธีตรวจสอบปริมาณการเข้าชม
