Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

9 Extremely Useful RSS Tricks and Snippets for WordPress

Last updated on by
Elegant Themes
9 Extremely Useful RSS Tricks and Snippets for WordPress

RSS is one of the core feature of WordPress and every other blogging platform. It is very useful because your readers keep track of your blog updates mostly by using RSS. In this article, we will show you some of the most useful RSS hacks, tips, tricks, and snippets for WordPress.

1. RSS Only Posts

There are times when people cannot afford to have a newsletter service like Aweber, but they still want to reward their subscribers. They still want to keep an incentive for subscribers, so your count keeps growing. This trick will help you create posts that is only shown to your RSS readers.

RSS Only Posts

You can achieve this by downloading the plugin called Advanced Category Excluder. Once installed, you should designate a specific category where you will post your RSS only posts. You can even name the category “RSS Only”. Then you need to go to the ACE Settings in your WP-Admin Panel and click on the feature Categories. Check in all boxes like Home, Archives for “RSS Only” Category, and leave the RSS Posts blank. This means that you have excluded RSS Only from being displayed in your home page, archives, and other places except for the RSS Feeds.

This is almost like a newsletter sent to just your RSS email subscribers and feed subscribers.

2. Control When Your Posts are Available Via RSS

Control When Your Posts are Available Via RSS

There are times when you publish a post and suddenly find an error. You can go back in the admin panel and change it, but it is already published in the feeds. With this hack, you can put a delay of as many minutes as you like, so you can double check the post live.

Open your functions.php and add this code:

function publish_later_on_feed($where) {
	global $wpdb;

	if ( is_feed() ) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');

		// value for wait; + device
		$wait = '10'; // integer

		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

		// add SQL-sytax to default $where
		$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
	}
	return $where;
}

add_filter('posts_where', 'publish_later_on_feed');

This code is adding a 10 minute delay on your post being shown on the RSS Feeds, you can change it by changing the number 10 to as many minutes as you like.

3. Insert Ads in Your RSS Feeds

Making money is the concept that everyone likes, but monetizing gets hard at times. This is just another way you can monetize by inserting ads in your RSS Feeds. Feedburner does it for you, but it is only Adsense Ads, and there is a subscriber count limit. This short snippet will help you insert ads, or anything else for that matters in your RSS Feeds.

Open your functions.php and add the following code:

<?php
function insertAds($content) {
$content = $content.'<hr />Check out Awesome WordPress Tips and Resources at <a href="http://www.wpbeginner.com">WPBeginner!</a><hr />';
return $content;
}
add_filter('the_excerpt_rss', 'insertAds');
add_filter('the_content_rss', 'insertAds');
?>

If you don’t have a functions.php file in your theme folder then simply create one. Once you have uploaded this file, you are now displaying ads in your RSS Feeds.

This hack uses an add_filter() function which does not modify your core files at all. Many other hacks ask you to modify your core files which is a bad idea because you will need to modify everytime when you reinstall WordPress.

4. Display Any RSS Feed on Your Blog

Display Any RSS Feed on Your Blog

There are often times when bloggers want to display RSS Feeds of other sites on their blog. Maybe it is from another blog of theirs that is related. This is when this hack comes handy because it makes your job much easier. There are several scripts and plugins that will do it for you, but you don’t need those because WordPress has this feature built in. And you should know that because you see the feeds in your Admin Panel Dashboard.

All you have to do is paste the following code where you want the feeds to be displayed. Most commonly placed in sidebar.php:

<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://feeds2.feedburner.com/wpbeginner', 5); ?>

Save the file and Upload it and you are done.

The function we used in this hack wp_rss is built in WordPress for future reference.

5. Exclude a Specific Category from RSS Feeds

Exclude a Specific Category from RSS Feeds

There are certain categories that contain maybe link love and others which most of your users are not interested in. This is the option to satisfy those users. You can exclude a specific category by using a plugin called Advanced Category Excluder, or you can do it manually by using the code below:

http://example.com/feed?cat=-5

To exclude multiple cateogries, just use the ampersand symbol:

http://example.com/feed?cat=-4&cat=-5

If you don’t want to use the plugin and don’t want to do it manually with the link. There is another way which you can use by editing your function.php. Paste the following code in it:

    function myFilter($query) {
    if ($query-&gt;is_feed) {
    $query-&gt;set('cat','-5'); //Don't forget to change the category ID =^o^=
    }
    return $query;
    }

    add_filter('pre_get_posts','myFilter');

6. Make a Separate RSS Feed for Each Category

Often times bloggers wonder how to make separate RSS feed for their category. Because sometimes your user only visits your website for the design category, but you have ten other categories that the user is not interested in. This hack will take care of this issue. (Source)

http://www.wpbeginner.com/category/showcase/feed/

All you have to do is add the word feed in front of the category URL, and it will take you to the feed for that specific category.

7. List RSS Feeds by Each Category

Last hack shows you how you can have a separate RSS Feed. This snippet will let you list your category feeds by each category.

List RSS Feeds by Each Category

<?php wp_list_categories('feed_image=http://www.wpbeginner.com/image.gif&feed=XML Feed&optioncount=1&children=0'); ?>

You must make sure to change the URL of the image because this will display RSS icon in front of each category.

8. Redirect WordPress Feeds to FeedBurner feeds.

We all want to have the most accurate subscriber count for our blogs. Feedburner provides us with a count of how many users have subscribed to the blog via feedburner feeds. Now WordPress by default has its own feeds to, so if someone types in yourdomain.com/feed then they should be sent to the WordPress version of the feed, and they can subscribe to that. But they will not be counted. One way you can solve this issue is by redirecting your WordPress feed to your FeedBurner feeds by using this short snippet of code:

Paste it in your .htaccess file located in the root folder.

# temp redirect wordpress content feeds to feedburner
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-] )?/?$ http://feeds2.feedburner.com/wpbeginner [R=302,NC,L]
</IfModule>

Make sure that you change the feed url to your FeedBurner url. This can also be done with a plugin called FeedBurner FeedSmith.

9. Disable RSS Feeds in WordPress

Do you want to use WordPress strictly as a static website. Then it might make sense that you disable your RSS Feeds. You can go to the wp-settings.php and remove one code but that will be stupid because it is a core file. Instead what you should do is use the following code and paste it in your functions.php

function fb_disable_feed() {
    wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
    }

    add_action('do_feed', 'fb_disable_feed', 1);
    add_action('do_feed_rdf', 'fb_disable_feed', 1);
    add_action('do_feed_rss', 'fb_disable_feed', 1);
    add_action('do_feed_rss2', 'fb_disable_feed', 1);
    add_action('do_feed_atom', 'fb_disable_feed', 1);

Source

Smashing Magazine


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Ben

    Helped me ! THX an lot !!!

  • http://www.GirlMeetsFood.com Mary

    Thanks so much! The Advanced Category Excluder is EXACTLY what I’ve been looking for for RSS-only info.

  • http://pudslife.com Rick Nielsen

    This is a great resource for WordPress. We only use WordPress for our clients sites and 5 of these tips have help us finish a project before the due date.

    Thanks so much and keep up the great work.

    • http://www.wpbeginner.com Editorial Staff

      We are glad that our resource was helpful :)

  • http://www.joyologo.com/ joyoge bookmark

    very useful intormations, thank you so much..

  • http://www.joannahaugen.com JoAnna

    Hello,

    I want to do #8 and #9 on my WordPress site (www.kaleidoscopicwandering.wordpress.com), but I can’t find any information anywhere about where to find this: functions.php … and then where to find this: .htaccess file located in the root folder.

    I use a WordPress theme (Digg 3), and I can follow the directions on how to switch the WordPress RSS for the Feedburner one (I’ve even signed up for the Feedburner URL already), but I have no idea where to find the code. Please help!

    Thank you.

    • http://www.wpbeginner.com Editorial Staff

      Your Functions.php should be in the theme folder. /wp-content/themes/yourthemename

      If it is not there, then make a new one.

      For #8 please use the plugin that we mentioned if you don’t can’t put the code in the .htaccess file.

  • http://www.fuelyourcreativity.com Angie Bowen

    Great article, thanks so much for putting it together! As much as I know about creating WordPress themes, customizing the RSS feeds is something I could definitely learn more about. I’ve bookmarked this for future reference.

  • http://designstrike.net Alex

    Very nice list, Digged and Retweeted keep up the nice job, btw love the fact that you can make a separate RSS feed for each category