Displaying RSS Feeds Using WP_RSS()

While WordPress allows you to include a RSS feed using the RSS widget you don’t have full control over where the RSS feed is displayed. Using the widget feature only allows you to add a feed where the theme author has designated that widgets can go. So what can you do when you want to display any RSS feed anywhere on your theme?

Use the wp_rss() function of course!

Fortunately the wp_rss() function is pretty easy to use and integrate into your theme. Let’s take a quick look at the code we will be working with:

<?php
include_once(ABSPATH . WPINC . '/rss.php');
wp_rss($uri, $num);
?>

As you can see, there isn’t a whole lot of code that we have to work with and that is what makes using this function quite easy. The first line of the code just includes a certain file from the WordPress core files that is required in order to properly parse and display the RSS feed.

The second line is where the configuration happens and where you will be changing both $uri and $num. $uri is the url of the feed that you are wanting to parse and display while $num is the amount of items that you want to display from that RSS feed. Quite simple huh?

So in order to display the 5 latest posts from this site the code would look like:

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

What is really nice is that the feed will already be formatted within <ul> tags and each feed item will be contained within a <li>tag, making it super easy to style to fit anywhere into your theme. This method is the simplest way to add a RSS feed into your WordPress theme as it doesn’t require the use of a plugin. The only downside is that only the hyperlinked title for the feed item is displayed and no other information.

If you are looking for further customization to displaying a RSS feed on your blog, the WordPress.org Plugin Directory is a great place to find tons of plugins. Or if you are already using WP 2.7 or above, which you should be, you can easily install any plugin from within the plugin page inside of your Admin Dashboard.

If you have any questions or issues and can’t get this to work on your own blog, make sure to leave a comment below or send me an email using the contact form.

Feedback!

If you read this post and understood it great! Let me know in the comments below. If you are still having issues and can't get it figured out, you are more than welcome to leave a comment or send me an email using the contact form and I'll do what I can to help!

Leave a Reply