As experienced WordPress developers, we've often needed to display RSS feeds from external sites—like another blog or news source—directly on a WordPress page. The great news? WordPress has a built-in fetch_feed() function that handles this natively, no plugins required. This approach is reliable, lightweight, and lets you turn your site into a seamless news aggregator.
Here's how to do it: Add the following PHP code to any template file, such as a custom page template (via Appearance > Theme Editor or a child theme).
<?php
// Include WordPress RSS fetcher
include_once(ABSPATH . WPINC . '/feed.php');
// Replace with your RSS feed URL
$rss = fetch_feed('https://example.com/feed.xml');
$maxitems = $rss->get_item_quantity(5); // Limit to 5 items
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>
<?php if ($maxitems == 0) : ?>
<li>No items.</li>
<?php else : ?>
<?php foreach ($rss_items as $item) : ?>
<li>
<a href="<?php echo $item->get_permalink(); ?>" title="<?php echo esc_html($item->get_title()); ?>"><?php echo esc_html($item->get_title()); ?></a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>Update the feed URL, item count, and add CSS for styling. This code is production-ready and follows WordPress best practices for security and performance.
Source: WordPress Codex