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

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.