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
HELLO,
A GOOD IDEA!
a pity in my case it doesn’t work. but i could use it. I did it like your instruction said. the code in the functions.php and the shortcode i did it in a widget text area.
what could the mistake be?
greetings
HI I was able to get the feed to successfully work. My only problem is i am going to be adding many feeds from different websites. In doing so, i need to add the website logo above each feed. No matter what i do in the code the feeds readjust to the top :
please help, thanks!
How would you add target _blank or make the link open in a new window?
I get it working now. Thanks for this article
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).