What’s better than an RSS Feed? Custom RSS Feeds of course! A lot of people have predicted the death of this sharing technology for eons now, but it is still going strong.
Statistics show that over 2000 of the world’s top 10,000 websites publish RSS feeds religiously. Feedly, a popular RSS feed aggregation service, grew its subscriber base by 900% in two years and revenue by more than 400%.
You might be interested in giving your visitors a customized user experience beyond your default WordPress RSS feed. Let’s explore how to customize your feeds to suit your website and audience.
Back Up Your Website
You’ll be going to your website’s back end, so back up your site. If anything breaks, you’ll still have your website, content, and settings intact. Don’t neglect this step, no matter what!
Also, we will be creating a new template file for your WordPress theme, so you might want to switch to/create a child theme so as not to mess up your existing theme.
Creating Custom RSS Feed in WordPress
To get started, we will be working with the “functions.php” file in your theme folder. Open it and paste the code below:
Note the section that asks you to type in your custom RSS feed’s name. Keep this name simple so that you can recall it easily as it forms your website feed URL. e.g., “https://yoursite.com/feed/mycustomfeedname.”
Note: Your custom RSS feed’s name can only be in small letters.
Create a Custom RSS Feeds Template
The custom RSS feed’s template is the information your feed will need to serve your feed. Think of it as an HTML/CSS kind of feature for your feed. To do this, you have to create another file with a unique name. This name MUST follow the convention: “rss-mycustomfeedname.php.”
Save this file in your child theme folder. Now open this file and paste the following code:
You can modify this file to show as many posts as you want. Use the
$postCount variable to change the number of posts to display. The default is showing “Posts,” but you can change it to show a different post type by changing the
$postType variable. The excerpts feature will also show excerpts for your posts. If your post doesn’t have excerpts it will show the first 120 words in the article.
Adding Functionality to the Custom RSS Feeds
Now that you have a functional template, you can add additional stuff to it.
Show Post Thumbnail in Feeds
If you want to include post thumbnails in your feed, copy and paste the following code to the bottom of your “functions.php” file.
If your post has a thumbnail image, this function will search for it and serve it together with your feed text. If it doesn’t have any image, then it does nothing.
Set Feed Language
Sometimes you may need to declare the language for your custom feed for it to work.
Do this by using this code in your “functions.php” file:
This will configure your language to English. If you intend to change it to another language, then edit the
en in the function code to your preferred language. Get a list of all language codes from this link.
Get Your Custom Feed Working
To get your custom RSS feed to work, you need to apply a rewrite flush to your WordPress system. All you need to do is go to “Settings -> Permalinks” and click “Save Changes.”
A Custom RSS feed is a great way to serve your content to people who may not have enough connectivity to access your full website. It also helps new audiences discover you through RSS feed apps on Android and iOS. You should absolutely give it a try.
Image credit: United Colors of Feeds