How to add a RSS Feed to a Post or Page Using a WordPress Shortcode
Last week I wrote about how the WordPress fetch feed function could be used to display RSS feeds on a website rather than using the RSS plugin.
While I was working on the articles it occured to me that a shortcode that provided this feature would actually be a lot easier and with the shortcode the feed could easily be used in a post or a page.
I was going to make my own and then realized that someone had probably already done so and made it available. And sure enough, the piece of code I needed was in the Mastering WordPress Shortcodes article at Smashing Magazine.
When I tested the code provided by Smashing Magazine, the RSS feed displayed at the top of the post even though the shortcode was at the bottom. This article, which is French, provided a minor change to the code, which corrected the problem.
The following code goes into your Theme functions, function.php, file:
<?php
//This file is needed to be able to use the wp_rss() function.
include_once(ABSPATH.WPINC.'/rss.php');
function readRss($atts) {
extract(shortcode_atts(array(
"feed" => 'http://',
"num" => '1',
), $atts));
ob_start();
wp_rss($feed, $num);
return ob_get_clean();
}
add_shortcode('rss', 'readRss'); ?>
Once this code is in your functions file, you can easily add a RSS feed to any page or post by adding the following shortcode.
[rss feed="http://feed url here" num="5"]
All you need to do is change the URL to the feed URL that you want to use. You can also change how many feed items are displayed.
Below is an example of using the WordPress shortcode to display my bookmarks tagged with WordPress on delicious.
- How to use your Gravatar as a favicon on your WordPress blog
- WordPress dashboard hacks for developers and freelancers | CatsWhoCode.com
- How to define a default post thumbnail
- WordPress › Ultimate Taxonomy Manager « WordPress Plugins
- Free E-Commerce WordPress Theme: Balita - Smashing Magazine
photo credit: misocrazy
Keep Reading:
Did you enjoy this article? I can assist you with your WordPress or Facebook project. Contact me and I will provide you with an estimate. You can also connect with me on Facebook or follow me on Twitter. If you are looking for Hosting, WordPress Theme, Newsletter or other recommendations, please view my detailed list.











January 28, 2010 at 11:26 am
An example of why? Instead of related posts maybe?
.-= Dennis Edell´s last blog ..The Time Has Come. The Deal Is Done. It’s Time To Move!! =-.
January 28, 2010 at 7:58 pm
Hi Dennis – You might be promoting a different website or have a collection of articles bookmarked that go along with the article.
I have a page of WordPress bookmarks that uses javascript provided by delicious – I could use this code instead.
January 30, 2010 at 10:36 am
OK so maybe a different type of “related posts” for certain posts…yes?
Speak simply…lol
.-= Dennis Edell´s last blog ..Hello & Welcome To The All New – DennisEdell.com/DirectSalesWebMarketing.com Merged – Direct Sales Coaching Blog! =-.
January 31, 2010 at 8:29 am
Hi Dennis – It sort of is. It depends on what feed you pull it.
March 22, 2011 at 7:41 am
This is a solution I was looking for some time, but unfortunatelly I have another one. There is an astrological service that displays on blank pages some text everyday. At midnight they change the text. I need to display that text on my blog, inside an article, using shortcodes.
Is there any way I can fetch that text exactly as an RSS Feed, even if it’s not an RSS Feed but just a normal page??? Please help!