How to Display RSS Feeds on Your WordPress Blog

Wonder how to display rss feed in your WordPress blog without using the deprecated wp_rss() function? Paste the following code 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.

<?php
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";
        endforeach;
        echo "</ul>\n";
    endif;
endif;
?>

Thanks to Dan Gayle for the best coding!

One Response to “How to Display RSS Feeds on Your WordPress Blog”

  1. IT Dude says:

    Thanks for the code, nice work!

Leave a Reply