How to Create an RSS Feed for Your Blog — 2 — The Basics
This is the second part in a series about creating an RSS feed for your website. Click here to read the first part about why you should have an RSS feed if you don’t already have one. In this part, I’ll be describing the basics of creating an RSS feed for your site, what should it include, how to let people know about it, and how you might want to syndicate content through it.
RSS is written in XML. Therefore, it’s a file composed of several tags with special meaning. The basic structure of an RSS file looks as follows:
The first line is a bit of boilerplate which identifies this file as using version 1 of XML and defines the text encoding that the file uses.
The next line is a bit of boilerplate which identifies the version of RSS we are using and “imports” the Atom namespace which allows us to use Atom tags in our RSS feed.
<channel> tag is a required bit of boilerplate and there can be only one per RSS 2.0 file. It encapsulates items and the feed metadata.
According to rssboard.org, having an
atom:link element, as seen on the next line, is highly recommended because it makes the feed more portable, self-contained, and easier to cache. The URL specified by the
href attribute should point to the location of your feed on the Internet.
<channel> tag, there must be at least a
<title> tag containing the title of your feed (e.g. “example.com’s Blog”), a
<link> tag containing a link to the site that the feed is for (e.g.
https://www.example.com), and a
<description> tag with a description of the feed (e.g. “The RSS feed for example.com”).
After the final required channel element,
<item> tags can be used to define individual entries in the RSS feed.
The Basic Format of a Post
Posts are fairly simple to format. They are defined in
<item> tags which generally look like this:
Most of the tags are straightforward.
<title> refers to the title of the post and is what will show up when someone is looking through a list of all items in the feed,
<link> is a link to the post on the Internet,
<pubDate> contains the date and time which the post was published and should look something like
Thu, 18 Jun 2020 20:01:46 -0400, and
<description> contains either the full content of the post, or just a description (if you choose to use Atom syntax, there are separate
All of those tags are technically optional in the
<item> tag. In fact, an
<item> tag is technically allowed to contain no elements at all so you’re free to pick and choose which bits of information you wish to include. A complete list of tags and their uses is linked in the Conclusion section of this post.
<description> tag, much of the accessibility and ease-of-use benefits of an RSS feed are realized when the
<description> contains the full text of the post. This allows someone to read your posts in their feed reader which means they don’t have to open a Web browser just to get the full version. It is highly recommended (by me, and many other folks on the internet) to include the full text of your posts in the
In order to include HTML text in the
<description> tag, you must either convert HTML markup to HTML entities (e.g.
>), or enclose the content of the description in a CDATA section which will look like this:
I personally use the CDATA method, as it allows me to easily copy and paste the HTML of my posts into the
How to Link to Your Feed
You may have seen the ubiquitous RSS Icon around the Web. Its use is so pervasive that it’s become like the floppy disk icon but for RSS feeds. Make sure that you prominently feature either this icon (or something like it) where people go to read your blogs, or provide a prominent link to where users can find your feed. For example, I have the icon on both my home page and my blog page.
Another standard that you should incorporate into your site is the use of a
<link> element in the
<head> of your HTML files. It’s a standard way to tell the user’s Web browser that an RSS feed is available for this site and where to find it. The element should look something like this:
As you can see, RSS really isn’t that complicated. You can get up and running with a feed for your site in less than a half-hour. It’s not even that hard to write it by hand, though that will get tedious over time. In the next post, I’ll talk about how I automate updates to my RSS feed and show you that it’s also really simple to automate updating the feed.
To learn more about available tags and what is and is not encouraged in RSS feeds, see the RSS Best Practices Profile.
This is my forty-ninth post for the #100DaysToOffload challenge. You can learn more about this challenge over at https://100daystooffload.com.