DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Do you ever wanted to be able to display any rss feed on your WordPress blog? If yes, here’s a simple code that will do the job without using the deprecated wp_rss() function.

The following code have to be pasted wherever you want to display the feed.
Don’t forget to update the feed url on line 3. Number of items to be displayed can be defined on line 6.

include_once(ABSPATH . WPINC . '/rss.php');
$feed = 'http://example.com/feed/';
$rss = fetch_feed($feed);
if (!is_wp_error( $rss ) ) :
    $maxitems = $rss->get_item_quantity(3);
    $rss_items = $rss->get_items(0, $maxitems);
    if ($rss_items):
        echo "<ul>\n";
        foreach ( $rss_items as $item ) : 
            echo '<li>';
            echo '<a href="' . $item->get_permalink() . '">' . $item->get_title() . "</a>\n";
            echo '<p>' . $item->get_description() . "</li>\n";
        echo "</ul>\n";

Thanks to Dan Gayle for the hack!


One Comment

  1. Thanks! it really helps a lot on my blog 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *