Using WordPress ‘get_rss()’ PHP function

The get_rss() WordPress PHP function displays RSS items in an HTML list.

Usage

get_rss( $url, $num_items );

Example:

get_rss( 'https://example.com/feed/', 10 );

Parameters

  • $url (string) – Required. URL of the feed to display. Will not auto sense feed URL.
  • $num_items (int) – Optional. Number of items to display, default is 5.

More information

See WordPress Developer Resources: get_rss()

Examples

Display RSS feed in unordered list

This example shows how to display the latest 5 items from an RSS feed in an unordered list.

<ul>
    <?php get_rss( 'https://example.com/feed/', 5 ); ?>
</ul>

Display RSS feed in ordered list

This example shows how to display the latest 10 items from an RSS feed in an ordered list.

<ol>
    <?php get_rss( 'https://example.com/feed/', 10 ); ?>
</ol>

Display RSS feed with custom item limit

This example shows how to display the latest 8 items from an RSS feed in an unordered list.

<ul>
    <?php get_rss( 'https://example.com/feed/', 8 ); ?>
</ul>

Display RSS feed from different sources

This example shows how to display the latest 5 items from two different RSS feeds in separate unordered lists.

<ul>
    <?php get_rss( 'https://example.com/feed/', 5 ); ?>
</ul>

<ul>
    <?php get_rss( 'https://another-example.com/feed/', 5 ); ?>
</ul>

Display RSS feed in a div container

This example shows how to display the latest 5 items from an RSS feed inside a div container.

<div>
    <?php get_rss( 'https://example.com/feed/', 5 ); ?>
</div>