Really Simple Syndication (RSS) is an incredibly simple yet powerful syndication technology. However, it’s common for WordPress users to run into problems with their RSS feed while using it.
Instead of installing plugins to overcome what may seem to be RSS limitations why not add a few lines of code to extend its functionality? In this post, we’ll cover some useful RSS tricks and hacks by introducing a problem, offering a solution, and explaining how it works.
Let’s get started.
Note: We’ve provided the PHP code for each trick and hack below. There are two ways of making the modification:
- Adding the code at the end of your theme’s functions.php file.
- Creating actions and filters.
1.Β Inserting Ads Into RSS Feeds
Integrating ads within your blog posts is a great way to promote products and monetize your blog.
The Problem
FeedBurner allows users to insert AdSense ads into their feed items if they have at least 500 subscribers. This hinders RSS feed monetization for users who use a different ad service or have under 500 subscribers.
The Solution
Paste the code given below to insert ads from different services into your functions.php
file:
https://gist.github.com/rafaysansari/e0069139074cf836fe1c1afe5ab19da8
Source: WP Recipes
How It Works
The ad’s HTML is appended to the original content of the post and returned to the insertAds()
Β function. This way, the content and the ad are both included when the RSS feed item is imported.
2.Β Providing RSS Feeds for Post Comments
Comments enhance the value your blog post delivers to its readers. They allow them to get insight into what others had to say about the content and give them a platform to share their thoughts.
The Problem
When a post receives tons of comments it can become difficult for the readers (and authors) to follow them.
The Solution
Thankfully, WordPress offers built-in functionality that provides an RSS feed for each post’s comments. All you have to do is make a function call to the post_comments_feed_link()
function.
https://gist.github.com/rafaysansari/ff36458ce58ce098dd6e75c1100b1229
Source: WP Recipes
How It Works
This line of code calls the post_comments_feed_link()
function that provides an RSS feed for the comments of a specific post. It makes it easier for your site’s readersΒ to keep track of the long list ofΒ comments.
3.Β Redirecting WordPress Feeds to FeedBurner Feeds
FeedBurner is a powerful and flexible web-based feed management provider.
The Problem
Most bloggers don’t start off with FeedBurner immediately but when they do, redirecting their existing viewership are already subscribed to their default WordPress feed. Shifting to the new platform at the risk of losing existing visitors isn’t feasible.
The Solution
All you have to do is add the following lines of code to your .htaccess
file:
https://gist.github.com/rafaysansari/b668362725cbd333e792da762f84aab6
Source: Perishable Press
How It Works
This code is a simple server redirection that redirects the user to your FeedBurner RSS when they try to access your default WordPress RSS. This ensures that your existing viewership won’t be lost when you shift to the FeedBurner platform.
4.Β Controlling Post Availability via RSS
By default, once you publish a post and it makes its way into your RSS feed, you can’t go back and modify it.
The Problem
You can modify a published post to correct a typo or make updates how many ever times you want, however, the changes won’t be visible in your RSS feed. The post displayed in your RSS feed will be the originally published piece. If a significant part of your traffic receives your blog posts through RSS, this can be a huge problem for your site’s credibility.
The Solution
The easy way to fix this problem is to delay the post from being added to your RSS feed. This means that the post will be published to your WordPress website before it is published to your RSS feed. Simply paste the following code into your functions.php
file:
https://gist.github.com/rafaysansari/8b61458f178ad25b1a3d1ec110e5c464
Source:Β WP Engineer
You can set the delay period to a different value – minutes, hours, days – depending upon your preference by modifying the wait
variable in line 9.
How It Works
The code given above sets the delay value inΒ the wait
variable to 10 minutes. This means that the post will be published to your RSS feed 10 minutes after you publish it to your WordPress website. If you make any changes to the post during the delay period, they will appear in the RSS feed once the post is published to it. Keep in mind that you’re still not actually modifying the post published to the RSS feed – you’re only giving yourself a chance to go back and make edits after the post has been published to your site.
5. Displaying Any RSS Feed
If you’re displaying RSS feeds on your WordPress blog then chances are you’re using a plugin. Did you know you WordPress offers built-in functionality that helps you get the job done without installing a plugin?
The Problem
Since plugins are external pieces of code, they need to be updated regularly and may even be incompatible with other plugins or themes that you have installed. Why install a plugin for the functionality you can easily include by adding some lines of code?
The Solution
Paste the following lines of code in your theme where you’d like to add the RSS reader:
https://gist.github.com/rafaysansari/ac26901a54c04bd57ee29a065be28275
Source: WP Recipes
You can add it to your themes header, footer, sidebar, or page template.
How It Works
The code given above picks up the rss.php
file from the WordPress core and includes it in your current theme. This file gives you access to use the wp_rss()
function which requires two parameters:
- The RSS feed’s URL.
- The number of RSS entries you’d like to have displayed.
6.Β Listing RSS Feeds by Category
WordPress categories help users classify and organize their blog posts.
The Problem
Have you ever wanted to be able to present your blog posts and content in a more organized manner? Allowing your readers to browse content based on a category enhances their user experience.
The Solution
Displaying a list of categories to your site’s RSS viewership is pretty easy. Paste the following line of code in your functions.php
file and you’re good to go:
https://gist.github.com/rafaysansari/e984170844f04bbff87472ff3160ea3d
Source: WPBeginner
How It Works
The line of code given above makes a function call to the wp_list_categories()
function which accepts two parameters:
- feed_image to specify the URL.
- feed which specifies the feed format.
7.Β Formatting Images for Feed Readers
Adding images to blog posts enhances the post’s visual appeal and makes it easier for the reader to digest content.
The Problem
When blog posts are displayed in feed readers they don’t look as great as they did on the website. This is because they are displayed inline with the text.
The Solution
The quick fix for this inevitable problem is to use a CSS class that will display each image as a block. The center
class in WordPress gets the job done seamlessly:
https://gist.github.com/rafaysansari/14a0afa56b072873f654d9d914979d61
Source: Pearsonified
How It Works
This CSS classΒ center
Β displays each image as a block and centers it in the RSS feed. This ensures that your images aren’t displayed inline with the text.
Wrapping It Up
Improving your RSS feed’s functionality with quick fixes and hacks gives you better control over the technology. Once you’re familiar with making quick edits you can customize them even further to make the most out of your RSS feeds.
Which RSS tricks and hacks did you find to be most useful?Β Weβd love to hear all about your experience so let us know by commenting below!
2 Responses
Thank for the great tips. Often don’t do much with the RSS feeds and this has given me some insight on how to better utilize these features.
The Problem: FeedBurner
The Solution: FeedPress
π