Official Ghost + Custom RSS Integration
Create Custom RSS Feeds in Ghost
Create custom RSS feeds for your publication using the flexible dynamic routing layer in Ghost and Handlebars templates.
Adding /rss/ to most URLs in Ghost produces an automatically generated rss feed, for example:
- Main post index - https://demo.ghost.io/rss/
- Author archive - https://demo.ghost.io/author/lewis/rss/
- Tag archive - https://demo.ghost.io/tag/fiction/rss/
Automatic rss feeds save time and allow external applications to access an up-to-date feed of your content. However, when the default implementation of rss feeds in Ghost doesn’t suit your requirements, you can create custom feeds using the dynamic routing layer and a Handlebars template.
Add an rss route in routes.yaml
In order to create a custom rss feed you’ll need to add a new route, which is the URL where your feed will appear.
Download the latest version of the routes.yaml file from Ghost Admin and open it in any code editor:
Under routes add the URL where your new custom rss feed will exist, for example:
routes:
/news/rss/:
template: news/rss
content_type: text/xml
Custom rss feeds need to be defined with the content_type property and mapped to a template as shown in the example above.
Create a new template
The next step is to create a custom template in your theme. Following the example above, create a new template with the file name: news/rss.hbs. Here’s a code example of what a custom rss template can look like:
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title><![CDATA[ {{@site.title}} ]]></title>
<description><![CDATA[ {{@site.description}} ]]></description>
<link>{{@site.url}}</link>
<image>
<url>{{@site.url}}/favicon.png</url>
<title>{{@site.title}}</title>
<link>{{@site.url}}</link>
</image>
<lastBuildDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</lastBuildDate>
<atom:link href="{{@site.url}}" rel="self" type="application/rss+xml"/>
<ttl>60</ttl>
{{#get "posts" limit="all" include="authors,tags"}}
{{#foreach posts}}
<item>
<title><![CDATA[ {{title}} ]]></title>
<description><![CDATA[ {{excerpt}} ]]></description>
<link>{{url absolute="true"}}</link>
<guid isPermaLink="false">{{id}}</guid>
<category><![CDATA[ {{primary_tag.name}} ]]></category>
<dc:creator><![CDATA[ {{primary_author.name}} ]]></dc:creator>
<pubDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</pubDate>
<media:content url="{{feature_image}}" medium="image"/>
<content:encoded><![CDATA[ {{content}} ]]></content:encoded>
</item>
{{/foreach}}
{{/get}}
</channel>
</rss>
You can copy and paste this exact implementation for your site, then go ahead and customize it to suit your needs!
Update your active theme and routes.yaml
Once you’ve saved your changes, upload your updated theme in Ghost Admin as a .zip file and upload your new routes.yaml file. That’s it, you’ve successfully created a custom RSS feed - you can test it out for yourself using the feed’s URL!
Advanced RSS Feeds for Podcasting
If you’re looking for more detailed examples specifically for generating an iTunes compatible podcast RSS feed, make sure you check out our in-depth podcast feed tutorial for Ghost, which builds on the things covered here!
Do More with Zapier
As always, you can power up your site even further using Zapier. Check out some of these powerful RSS automations:
Create new Ghost posts from fresh items in RSS by Zapier feeds
Generate rss items for every new post published in Ghost
Create posts in Ghost from new items in multiple feeds with RSS by Zapier
Launch Your Big Idea
Last week, 10,603 brand new publications got started with Ghost. Today, it's your turn.