How to create the perfect RSS feed with Drupal 9

RSS is a great way to syndicate your content, but setting up a feed correctly displaying your articles can be tricky. In this blog post I will show you how to use Views to build the perfect feed in Drupal 9.
Robert Roose
By Robert Roose

How to create the perfect RSS feed with Drupal 9

Before we start

In this example I will show nodes in a RSS feed of the ‘Article’ content type, which I’ve already created. This article content type contains an Image field (learn how to efficiently reuse your image fields) and a Summary field of the type Text (formatted, long). I prefer using a separate Summary field instead of the default Body with the built in summary option, because this gives me more flexibility.  

It’s also highly advisable to install the Publication Date module. This will add an extra field to your content type containing the date the node was actually published. You will need this date to correctly display nodes in a feed.

You can also use the creation date, but this might not always be the date stamp you want your nodes to have. If, for example, you’ve started a draft and finally publish the node a few days or weeks later, the creation date will lag behind the actual publish date. This can mess up the way your articles are displayed in an aggregator such as Planet Drupal.

Creating the perfect feed with Views step by step

  • In order to validate our feed we need to display the date on which the article was published in a specific format. So first navigate to Configuration > Date and Time formats
  • Click Add format
  • Name the date format RFC822 as this is the format we need to comply to
  • Use the following as the Format string
    D, d M y H:i:s O
  • Click Add format
  • Navigate to Structure > Views
  • Click Add view
  • I will name the view RSS Feeds
  • Below View settings set Show: to Content and of type to the type of content you want to show. In this example I will choose the Article content type. Leave sorted by to newest first
  • Click Save and edit
  • Next to Master click on + Add and select Feed
  • Click on None next to Title.
  • Check Use the site name for the title or fill in the title you want the feed to show in RSS readers
  • Click Apply
  • Click on No path is set next to path
  • Enter the path you want your RSS feed to be shown at. I choose feed.rss but you can also us blog.rss or articles.xml
  • Click Apply
  • Click on Content next to Show below Format
  • Select Fields
  • Click Apply
  • On the next screen click Cancel. This seems counterintuitive but we will fix this in a later step
  • Below Fields click on Content: title
  • Uncheck Link to the content
  • Click Apply
  • Next to Fields click Add
  • In the Search field enter published and select Published on
  • Click Add and configure fields
  • Below Date format select RFC822 format
  • Click Apply
  • Next to Fields click Add
  • In the Search field enter image and select Image (see my comment about this image field above)
  • Click Add and configure fields
  • Below Formatter select Thumbnail
  • Below Image style select Thumbnail
  • Click Apply
  • Next to Fields click Add
  • In the Search field enter summary and select Summary (see my comment about this summary field above)
  • Click Add and configure fields
  • Click open Rewrite results
  • Check Override the output of this field with custom text
  • Enter the following below text:
    {{ field_summary }}
    {{ field_image }}

    This will display the summary and the image in the same field, making it possible for the image to get picked up by RSS readers such as Feedly.
  • Click Apply
  • Next to Fields click Add
  • In the Search field enter id and select ID (in the Content category)
  • Click Add and configure fields
  • Uncheck Display prefix and suffix
  • Click open Rewrite results
  • Check Override the output of this field with custom text
  • Enter the following below text:
    node/{{ nid }}
    This will be used as an unaliased link to the nodes
  • Click Apply
  • On the right side click open Advanced
  • Click on Add next to Relationships
  • Select Content author
  • Click Add and configure relationships
  • Click Apply
  • Next to Fields click Add
  • In the Search field enter name and select Name (in the User category)
  • Click Add and configure fields
  • Below Formatter select Author name and uncheck Link to the user
  • Click Apply
  • Click on Settings next to Show below Format
  • Below Title field select Content: Title
  • Below Link field select Content: ID
  • Below Description field select Content: Summary
  • Below Creator field select (author) User: Name
  • Below Publication date field select Content: Published on
  • Below GUID field select Content: ID
  • Click Apply
  • You also want to disable caching for your feed so if you make a change aggregators will immediately pick it up. You can do this by first clicking open the Advanced tab on the right side
  • Click on Tag based next to Caching
  • Select None
  • Click on Apply
  • Save the view by clicking on Save

Now you can check if your feed validates, which it should. Or you can see how your feed is displayed in an RSS reader by adding the feed (using the URL) to Feedly

If you have any questions about the above please let me know by leaving a comment.

Don’t forget to follow my Drupal RSS Feed or sign up to my Drupal newsletter.

More Drupal tutorials

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.

Comments

Since it's on topic, I'd love it if you had the content of your writing in your RSS feed. All I get in The Old Reader is the title, first sentence, and photo, so I usually only read the first sentence of your blog posts.

Hi Greg,

I understand, but I like people to come to my website to interact, such as giving comments, subscribing to my newsletter or viewing related content.

But especially for you I've created a full version of my feed. You can check it out here: https://robertroose.com/drupal-full.rss

Let me know if this works for you :)

thanks! With the end of Google reader, I bet RSS isn't a big source of traffic. Interestingly, to get the feed to work, I had to load the feed in a browser first before Old Reader would accept it, but it's working now. Thanks Robert! I love the posts. We talked about your 50 Drupal modules post in the Fox Valley meet up.

~G

For related content and the link to comment, if you include those in your RSS feed too, folks who do subscribe via RSS should get all the things you would want them to read in the browser. Basically, the only thing that doesn't work in RSS is JavaScript based advertisements like Adsense.