Posted on 27 January, 2010 By Kim Woodbridge 4 Comments

How to add a RSS Feed to a Post or Page Using a WordPress Shortcode

 
Share

Short stranger (by misocrazy)

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.

photo credit: misocrazy


Related Posts:
  • How to Add a RSS Feed Without a Plugin Using the WordPress Fetch Feed Function
  • 8 WordPress Shortcodes
  • How to Import Your WordPress Blogroll or Links From One Site to Another
  • How to Create Your Own WordPress Shortcode
  • How to Style the Read More Link in WordPress
  • Posted In : WordPress Tips
    If you enjoyed this post, please subscribe to my RSS Feed. You can also connect with my Facebook page or follow me on Twitter.



    4 Responses to “How to add a RSS Feed to a Post or Page Using a WordPress Shortcode”

    Leave a Comment
    You may use: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

    CommentLuv Enabled

    Recent Comments

      • Ari Herzog: Agreed on the updates/inbox snafu. I rarely see page updates and I know where they are! .-= Ari Herzog´s last blog .....
      • jayson: Kim, Love the themes. I am looking to update the theme on my site to something more appropriate. My site is all abou...
      • vered: "I wish more people would use this. I think it’s silly when I get updates for things occuring in Kansas and California –...
      • Dennis Edell @ Direct Sales Marketing: I was speaking generally, not specifically this month. how exactly do you work things? .-= Dennis Edell @ Direct Sales M...
      • Lucy Beer: Unfortunately I think next to no-one actually sees those "Updates". They're buried in a subsection of the inbox and I do...
      • Kim Woodbridge: Hi Marbella - Thanks! I had a great time....
      • Kim Woodbridge: Hi Julie - I'll probably try kayaking again next summer but I don't know if I will become much of a kayaker - I had a di...
      • Kim Woodbridge: Hi Vered - If you ever get the chance, you should go. It's like a different world - it's so quiet and peaceful....

    About

    Kim Woodbridge is an accomplished Information and Technical Consultant specializing in the entire implementation of a WordPress based website including installation, theme design, upgrades, unique customizations and ongoing site maintenance.

    Wordpress Services

    • Installation, upgrades and maintenance
    • Conversion of existing html and css templates
    • Theme and plugin recommendations
    • CSS customizations
    • Troubleshooting and tweaks for unique situations
    • Customization for individual blogging goals and needs
    • Training and advice