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

How to Embed an External RSS Feed in WordPress Posts via Shortcode

Last updated on by
Elegant Themes
How to Embed an External RSS Feed in WordPress Posts via Shortcode

Have you ever seen showcases like 25 best XYZ sites to follow? Usually these tutorials have the site name, site screenshot, a small description, and the list of recent posts. The main issue with those posts are the list of recent posts which gets outdated overtime because most authors manually create those links at the time of writing. That post is really outdated as soon as any one of those other sites publish a new post. Well in this article, we will show you how to embed an external RSS feed in WordPress posts via shortcode, so you can keep your list posts relevant.

First thing you need to do is open your theme’s functions.php file and paste the following code:

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

    return wp_rss($feed, $num);
}

add_shortcode('rss', 'readRss');

Now all you have to do is use this shortcode when writing a post:

[rss feed="http://feeds.feedburner.com/wpbeginner" num="5"]

Make sure you change the feed URL in the shortcode to what you want. You can also adjust the number to your liking.

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 »
  • MerryLeigh Giarra

    How would you add target _blank or make the link open in a new window?

  • Albert Israel

    I get it working now. Thanks for this article :)

  • murkee

    Very interesting, but did you know wp_rss is deprecated, and they recommend the use of fetch_feed instead?

    What I often think is needed with custom shortcodes is a bit of code which tells WP to behave gracefully with unrecognised shortcodes (especially useful when themes change).