10 Useful RSS-Tricks and Hacks For WordPress

Advertisement

By Jean-Baptiste Jung

RSS is one of those technologies that are extremely simple yet extremely powerful. Currently, RSS is the de facto standard for blog syndication, and it is used widely in both personal and corporate settings; for example, in blogs. And because a large percentage of these blogs run on WordPress, we’ll cover in this post some (hopefully) relatively unknown but useful RSS-related tricks and hacks that will help you use RSS in a more effective way — and without unnecessary and chunky WordPress plug-ins.

Let’s take a look at 10 useful, yet rather unknown RSS-tricks for WordPress. Each section of the article presents a problem, suggests a solution and provides you with an explanation of the solution, so that you can not just solve some of your RSS-related problems but also understand what you are actually doing. Thus, you can make sure your WordPress theme remains under your control and is not bloated with some obscure source code.

1. Control When Your Posts are Available via RSS

Screenshot

The problem. Have you ever published an article and then immediately noticed an error? Sure, you can edit it, but there’s another problem: the article has already been published in your RSS feed. To avoid this kind of problem, use this recipe to create a delay between the publication of a post and its availability in your RSS feed.

The solution. To apply this hack, simply paste the following code into your theme’s function.php file. If your theme doesn’t have this file, just create it.

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 = '5'; // 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');

Code explanation. The above code will add a 5-minute delay to the time between when your post is published on your blog and when it appears in your RSS feed. To change the length of the delay, change the value of the $wait variable on line 9.

Sources

2. Redirecting WordPress Feeds to FeedBurner Feeds

Screenshot

The problem. Beginner bloggers usually start to use FeedBurner only after they have seen it used on many other blogs and realize how useful and cool this tool is. They sign up and start to use it, but their early readers are already subscribed to their default WordPress feed.

Another problem: do you often change your theme? If so, you must be bored having to edit each call to bloginfo(’rss2_url’) and replace it with your FeedBurner feed’s URL.

The solution. The solution to both problems described above is simple: use server redirections.

  1. Create a backup of your .htaccess file, located in the root of your Web server.
  2. Edit the .htaccess file and add the following code. Don’t forget to modify the feed’s URL with your own feed’s URL.
    # 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://feeds.feedburner.com/wprecipes [R=302,NC,L]
    </IfModule>
  3. Save the file. You’re done!

Code explanation. Each time someone clicks on a link to http://www.yourblog.com/feed, he or she will be redirected to http://feeds.feedburner.com/yourblog. This way, you will have never lost an RSS subscriber, and even if you change your theme twice a day, you’ll never have to manually edit your RSS feed links again.

Sources

3. Insert Ads (or Anything Else) in Your RSS Feed

Screenshot

The problem. Monetizing RSS feeds is currently becoming a common practice, and many blog owners do it to maximize their income. FeedBurner can insert AdSense ads into your feed items, but you need at least 500 subscribers to qualify, and you can’t use any ads other than the AdSense ads provided by FeedBurner.

The solution. It is possible, though, to insert other kinds of ads into your RSS feed. You can, for example, use a link to a free WordPress theme only for your RSS subscribers.

Follow these simple steps to perform this hack:

  1. Edit the functions.php file of your theme. If your theme doesn’t have a functions.php file, simply create one.
  2. Paste the following code into your functions.php file:
    <?php
    function insertAds($content) {
        $content = $content.'<hr /><a href="http://www.wprecipes.com">Have you visited WpRecipes today?</a><hr />';
        return $content;
    }
    add_filter('the_excerpt_rss', 'insertAds');
    add_filter('the_content_rss', 'insertAds');
    ?>
  3. Save the file. You’re now displaying your ads in your RSS feed!

Code explanation. I have seen many similar hacks on the Web, but all of them require you to edit WordPress core files to achieve the same result. Of course, editing WordPress core files is a very bad idea because then you would have to re-edit the files each time you upgrade your blog. Instead, this hack uses the add_filter() WordPress function to insert content into your RSS feed without editing any core files.

Sources

4. Format Your Images for Feed Readers

Screenshot

The problem. You took a lot of time to write and format your post and add beautiful screenshots. It looks so good on your blog. Sadly, when the post is displayed in Google Reader or any other RSS reader, it doesn’t look so great.

The solution. This is due to the fact that most feed readers display images inline with text:
inline image
To avoid this problem, add a CSS class to display the image as a block. WordPress provides the built-in class “center“:

<img src="http://www.smashingmagazine.com/images/wordpress-rss-hacks/myimage.jpg" alt="This is my image" class="center"/>

Sources

5. Provide Your Readers with a Feed for Each Post

Screenshot
The problem. When a post has lots and lots of comments, it can be hard for readers to follow the conversation. Most WordPress users don’t know this, but our favorite blogging engine has a built-in function for providing an RSS feed for the comments in each post.

The solution. Well, this recipe isn’t really a hack or anything: to provide an RSS feed for the comments in a particular post, just call the comment_rss_link() function:

<?php comments_rss_link('&raquo; Comments RSS Feed'); ?>

Sources

6. Exclude Categories from Your RSS Feed

The problem. Do you use one of your blog categories to let readers know about your website’s news, or does your blog feature a category that has nothing to do with the rest of your content? If so, it is generally not a good idea to include it in your RSS feed.

The solution. Here’s how to get rid of one of the categories in your RSS feed:

  1. First, get the numeric ID of the category you want to exclude. If you don’t know how to get the ID of a particular category, you can learn how here8.
  2. Once you have the ID of the category you want to exclude from your RSS feed, edit the functions.php file in your theme. Create the file if it doesn’t exist.
  3. Paste the following code in it:
    function myFilter($query) {
        if ($query->is_feed) {
            $query->set('cat','-5'); //Don't forget to change the category ID =^o^=
        }
    return $query;
    }
    
    add_filter('pre_get_posts','myFilter');
  4. Save the file, and you’re done!

Code explanation. This hack works exactly the same way as the previous one: create a custom function to exclude the category that you don’t want to appear in your RSS feed, and then use the super-useful add_filter() function to apply it to the pre_get_posts() WordPress core function.

Sources

7. Display Any RSS Feed on Your WordPress Blog

Screenshot

The problem. Do you have more than one blog, or do you manage a forum? If so, you may want to be able to display any RSS feed on your WordPress blog.

The solution. Many plug-ins can do the job, but they’re not necessary at all. WordPress has a built-in RSS reader that is used, for example, to display news on your dashboard. All you have to do is use it in your theme.

  1. Paste the following code anywhere in your theme (personally, I’d put it in the sidebar, the footer or, even better, the page template11):
    <?php include_once(ABSPATH.WPINC.'/rss.php');
    wp_rss('http://feeds.feedburner.com/wprecipes', 3); ?>
  2. Save it and you’re done. It’s as easy as that!

Code explanation. The first thing we have done is include the rss.php file from WordPress core. This file allows us to use the wp_rss() function, which takes two parameters: the first is the RSS feed’s URL, and the second is the number of RSS entries to be displayed.

Sources

8. Use Category-Specific RSS Feeds

Screenshot

The problem. Many blogs talk about a lot of different topics: design, programming, blogging tips, etc. Have you ever come across a blog in which you have enjoyed only one category of posts? If so, you should definitely consider offering one feed per category to your own readers.

The solution. Let’s say you’d like to be able to subscribe only to TheGridSystem’s tools section13. The category URL is:

http://www.thegridsystem.org/categories/tools/

To get an RSS feed for this category, you simply have to add /feed to the end of the URL:

http://www.thegridsystem.org/categories/tools/feed

Pretty easy, isn’t it? But pretty useful, too, in my opinion.

9. List RSS Feeds by Category

Screenshot

The problem. If you like the previous hack, you will probably also want to be able to display the names of all your category feeds in a list to your readers.

The solution.

  1. Edit any of your theme files, where you want to list your categories and their accompanying feeds.
  2. Paste the following code:
    <?php wp_list_categories('feed_image=http://www.myblog.com/image.gif&feed=XML Feed&optioncount=1&children=0'); ?>
  3. Save the file. You categories will now be displayed, along with their RSS feeds!

Code explanation. This hack uses only the good old wp_list_categories() function, with two parameters. The first is feed_image, which allows us to specify the URL to be displayed as a feed image. The second parameter is feed, which is used to specify the feed format.

10. Get Rid of RSS Feeds the Clean Way

Screenshot

The problem. Let’s say you’re using WordPress as a CMS to manage your online portfolio or your company’s website. In such cases, the RSS feed isn’t that useful, and some people would probably want to remove it.

The solution. I have seen many “hacks” on the Web where people say you just have to remove the include on the wp-settings.php core file. I don’t think you should ever edit a core file. Instead, the following hack will do the job. Simply paste this code in the functions.php file of your theme:

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);

Sources

(al)

Footnotes

  1. 1 http://wpengineer.com/publish-the-feed-later/
  2. 2 http://perishablepress.com/press/2008/03/25/redirect-wordpress-feeds-to-feedburner-via-htaccess-redux/
  3. 3 http://www.wprecipes.com/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-htaccess
  4. 4 http://www.wprecipes.com/how-to-insert-ads-on-your-rss-feed
  5. 5 http://www.webinventif.fr/wordpress-ajouter-du-contenu-dans-son-flux/
  6. 6 http://www.pearsonified.com/2007/06/how-to-format-images-for-feed-readers.php
  7. 7 http://www.wprecipes.com/wordpress-how-to-provide-rss-feed-for-each-post-comments
  8. 8 http://www.wprecipes.com/how-to-find-wordpress-category-id
  9. 9 http://www.jangro.com/a/2008/03/01/excluding-posts-from-your-blog-feed/
  10. 10 http://www.wprecipes.com/how-to-exclude-categories-from-your-rss-feed
  11. 11 http://www.wprecipes.com/how-to-create-and-use-wordpress-page-templates
  12. 12 http://www.wprecipes.com/how-to-display-any-rss-feed-on-your-wordpress-blog
  13. 13 http://www.thegridsystem.org/categories/tools/
  14. 14 http://wpengineer.com/disable-wordpress-feed/

↑ Back to top Tweet itShare on Facebook

This guest post was written by Jean-Baptiste Jung, a 28-year-old blogger from Belgium, who blogs about Web Development on Cats Who Code, about WordPress at WpRecipes and about blogging on Cats Who Blog . You can stay in touch with Jean by following him on Twitter.

Advertising
  1. 1

    Real cool tutorial except I am having problems with adding the ads into my wordpress rss feeds. Help! I am @ olsayings.com

    0
  2. 102

    What if you have a create a newsletter where you are supposed to have first article from Category 1 and 4 articles from category 2. Is it possible via hack. I am using Mailchimp and Yahoo pipes but none can sort as we are not publishing category name in rss. How to publish category name in RSS ?

    0
  3. 203

    Here is a great plugin for anything related to RSS on WordPress: http://www.wizardrss.com

    0
  4. 304

    Great tips! I do have one question if someone out there can maybe help me.

    How do I stop people from syndicating my blog? Without having to remove RSS completely.

    0
  5. 405

    Hi

    Does anyone know how to tell WordPress to publish the RSS feed (I moved from Blogger) to the RSS.xml file instead of it’s own made up /feed/ directory which isn’t actually a XML file

    thanks for your help guys

    0
  6. 506

    Very useful post for me. In fact we are in to WordPress customization.

    0
  7. 607

    Hi Jean;

    Man, I’ve found your article quite helpful, so much so, that I told all my readers about it in my blog NestorPabon.com.

    One other useful tip is to put your article’s keyword and anchor text in the opening paragraph. That way once your article gets syndicated you will get linkjuice to your sites’ post.

    I also like to use Yet Another Related Posts Plugin because it allows me to also syndicate related posts thus giving me more backlinks.

    Again, thank you for the great article.

    0
  8. 708

    Great snippets of code and always useful to come across this sort of thing. I’m looking for a similar feed setup that will allow me to place 4 or 5 different feeds on a page from different organisations and have then each display in a scroller. anyone have any ideas how to do this?
    You gotta love WordPress.

    0
  9. 809

    thank you sir! brilliant post!

    0
  10. 910

    thank you!

    0
  11. 1011

    thank you, from me too!

    0
  12. 1112

    Stockport Web Design

    August 3, 2010 6:56 am

    Regarding number 8 above…

    I don’t get images in the feed when I apply this category feed, but I do in the main one.

    Any ideas?

    0
    • 1213

      Stockport Web Design

      August 4, 2010 2:29 am

      never mind – sorted it.

      just need to figure out now how to use full size images in the feed… =/

      0
  13. 1314

    Here is some code you can use to pull feed listings from anywhere. The positive benefit is that this short code can be styled and moved around in your WordPress post.

    You use the same short code rss feed=”http://rss.news.yahoo.com/rss/entertainment” num=”5″]

    But instead place the following code in functions.php

    //This code is needed to use the wp_rss() function.
    include_once(ABSPATH.WPINC.’/rss.php’);
    function readRss($atts) {
    ob_start();
    extract(shortcode_atts(array(
    “feed” => ‘http://’,
    “num” => ’1′,
    ), $atts));
    wp_rss($feed, $num);
    $output_string=ob_get_contents();
    ob_end_clean();
    return $output_string;
    }
    add_shortcode(‘rss’, ‘readRss’);

    Hope that helps

    0
  14. 1415

    I love this info. It’s great and very well layed out. I will use soem of the tips on my Learn to Sing site. Thanks again

    For more tips on Learning to Sing and Singing Lessons download vocalwarmup.co.uk’s FREE eBook “90 Days To Be A Better Singer” and join our Newsletter.

    0
  15. 1516

    thanks, very helpfull!

    0
  16. 1617

    Great list…

    Quick question- Can we show the RSS feed with the title of the post in the aggregator (like google reader or feed burner) but disable the link to the actual post. So, we basically want to show the results of the feed as a list of items with out any links to the actual posts.

    ~Kiran

    0
  17. 1718

    Very nice , but,…

    i have many blogs ,.. 4 o 5 wordpress and i want to translate all these blogs to post on the main blog ,…

    how can i take the rss and create daily post from this rss ?

    0
  18. 1819

    wow. very usefull! I will use your tricks for my web site. Thanks a lot for the help!!

    0
  19. 1920

    i like the picture at number 4 in the tutorial :)) the doggies, awww so cute :) sorry for the offtopic.

    0
  20. 2021

    Thank you for the useful tips…

    0
  21. 2122

    thank you for great info.
    This is really very useful for wordpress user.

    0
  22. 2223
  23. 2324

    Per “5. Provide Your Readers with a Feed for Each Post”

    Is there a way to crate an RSS feed for individual posts, rather than just the comments?

    Our posts are updated often and we want to enable our users to subscribe to specific posts alone.

    0
  24. 2425

    rmalinks wAfter following this tutorial, I couldn’t get a couple of things to work. The permalinks will not work with the register_post_type() and arrays outlined in a function; I simply removed this and peorked fine

    0
  25. 2526

    One of those posts that is very helpful and every WordPress user should have in their bookmarks.

    0
  26. 2627

    Very useful information.
    Thanks for this post.

    Reklam Ajansı

    0
  27. 2728

    Thanks a lot for sharing this information!
    Keep it up

    0
  28. 2829

    Hi,

    thank you very much for the insight!

    I have been searching to finde a way to hide the author’s name from the feed. Does anybody know where I would need to insert what kind of function. Or is there a standard template where I could simply delete that field?

    0
  29. 2930

    How can I create a RSS which has all the pages in my blog.. am not looking to include pages into normal blog post RSS but a seperate feed which shows only pages.. Thanks

    0
  30. 3031

    RSS is a better tool for business owners and these tips will be really helpful for them.These tips will also be useful for people who are introducing the new websites as news websites make good use of RSS feeds to draw in customers.
    mlmleadsystempro

    0
  31. 3132

    great article i like it. It will help a lot to many peoples who are interested in wordpress rss.

    0
  32. 3233

    Huzefa Muhammad

    March 7, 2011 2:58 am

    great post. point number 7 that is displaying any rss feed on your blog, does it mean that you can add the content of any other blog on your site??? it this thing similar to the wp-robot????

    0
  33. 3334

    Thanks for the post – I have looked a lot of places for some simple information about RSS. This post was excellent.

    0
  34. 3435

    Best list of hacks ever! Thank you

    0
  35. 3536

    This is a great post. I never new that you can manage the feeds in this way.

    0
  36. 3637

    I really like the post and I am looking for some material on the RSS feed.This post is quite handy in enhancing my knowledge.
    Expecting some more good ones in near future…
    Mike Dillard

    0
  37. 3738

    Great article, I was looking for separate RSS feeds for all categories on my blog and I am going to try the hack explained in this article. Hope that works :)

    0
  38. 3839

    Great. Thank you!

    0
  39. 3940

    cool, very helpful for me.

    0
  40. 4041

    Is there any plugin or hack that I can use to display multiple RSS feeds on my WordPress site?

    For example, how do I display news excerpts from CNN, Reuters, NYT, etc?

    Possible to display specific feeds based on keywords? For example, Pinterest?

    Would be most grateful to get an answer as I have been searching high and low for the past week. Thanks in advance.

    0
  41. 4142

    Solutiion no. 1 is very useful for me. In deed it often happens to me that I find a mistake after posting. Thanks for your tips!

    0

↑ Back to top