Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Display Any RSS Feed on Your WordPress Blog

There are times when you want to display external RSS feed on your blog. Perhaps a blog feed of your another blog or some other site. Well you do not need a plugin to do this because WordPress have a function built in that will take care of this. In this article we will show you how you can display an external RSS feed on your blog. This way you can even use WordPress as a news aggregator.

Simply paste the following code in any WordPress file that you choose. Preferrably in a custom page that you create.

<h2><?php _e( 'Recent news from Some-Other Blog:', 'my-text-domain' ); ?></h2>

<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );

// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'https://www.wpbeginner.com/feed/' );

if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly

    // Figure out how many total items there are, but limit it to 5. 
    $maxitems = $rss->get_item_quantity( 5 ); 

    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items( 0, $maxitems );

endif;
?>

<ul>
    <?php if ( $maxitems == 0 ) : ?>
        <li><?php _e( 'No items', 'my-text-domain' ); ?></li>
    <?php else : ?>
        <?php // Loop through each feed item and display each item as a hyperlink. ?>
        <?php foreach ( $rss_items as $item ) : ?>
            <li>
                <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
                    title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">
                    <?php echo esc_html( $item->get_title() ); ?>
                </a>
            </li>
        <?php endforeach; ?>
    <?php endif; ?>
</ul>

Make sure you change the feeds url and the quantity and any other setting that you like.

Source: WordPress Codex

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

32 CommentsLeave a Reply

  1. I have a wordpress site, and I started a new page and inserted the above in the ‘text’ screen. So I am new to this and the ‘visual’ part of the coe is showing as below. I have max items of 10. What do I do now?

    $rss_items = $rss->get_items( 0, $maxitems );

    endif;
    ?>

    get_permalink() ); ?>”
    title=””>

  2. Hello Sir ! Thank you so much for this code.. I’m also looking for same issue to implement feeds from external URL to my wordpress website. I have been successfully integrated all feeds from external URL to my website. But there is no thumbnail image is appearing with posts.. Can you please help me ?? I just want to show thumbnail image with feeds.

    Thanks in advance…

    • Let’s try that again… forget that my sample code would be executed :)
      The code should look something like this:
      <a href=”…” title=”…” target=”_blank”> … </a>

  3. Hi, thanks so much for this, very useful. I am trying to customise it to display the post summary as well as the title but not successful – is there an easy way to customise it for this? Thanks!

  4. Is there a way to take only a certain category out of the feed and show that? I have a site where the client has the blog at a different URL. On certain pages, they want posts that are relevant. Thanks for any direction!

  5. Hi,

    How to add several RSS feeds from same (but different categories) or different websites with their thumbnail of feature image?

    Thanks in advance.

  6. Am also trying to add content, but a shortened version with html removed or integrated.

    I have just added get_content() ); ?> but the whole content is retrieved with untreated html markup.

    Have you got an easy way to set it up? like you’ve already written it down somewhere? :)

    and thanks a lot for sharing this script in the first place!

  7. Thanks for the code, I added a few bits and pieces to fit my project namely (I’m no php lord so if I’ve done something crummy let me know):

    1. Excerpt
    2. Strip HTML tags and images from excerpt
    3. Add read more button

  8. I have tried this code and cant get it to work, does it only work on a wordpress.org site? we have set up a wordpress.com and I want to display the rss feed of a sport club on a specific page and not in a widget on all pages.

    Thanks in advance
    Zach

  9. I want to display, the content(full article and picture) from a sport club to my website that will have forum where members can interact. I tried normal RSS feed code from the club site but it does not display enough content and no pictures.
    Please what can I use.

  10. hi please help me I have an error on my wordpress site

    SimplePie reported: cURL error 28: Operation timed out after 10000 milliseconds with 0 bytes received

  11. I want to receive feeds from several sources and then i want to distribute that content into categories and subcategories. How can i do this in my wordpress blog. Do you have any idea?

  12. Hello

    Is there any plugin or hack that I can use to display multiple RSS feeds on my WordPress site?

    For example, how do I display news excerpts from CNN, Reuters, NYT, etc?

    Possible to display specific feeds based on keywords? For example, Pinterest?

    Would be most grateful to get an answer as I have been searching high and low for the past week.

    Thanks in advance.

    • You can use a plugin called FeedWordPress (We used it a while ago). People are reporting that it is broken, but you can give it a try. Alternatively, use Yahoo Pipes to combine all of your feeds. Then use the pipes feed to display it on your blog.

      Admin

  13. What alterations in the code should i do in order to fetch the feed from multiple links?

    Thanks

    • Not sure if you can do that with this code alone. You would have to use something like Yahoo Pipes or another combine all the feeds into one. Then use it with this code. Alternatively, there are plugins like FeedWordPress that lets you do what you are talking about.

      Admin

  14. Yes but: discovering a feed depends on the server the feed emanates from. Since you will want to display several feeds from several different sites, if at some point ONE server is slow or down, the code will get stuck. This has been the weakness of many feeds plugins.

    • Its good to show data from other websites, if you run a sports blog you can to a custom page or your own sidebars and title it like “Espn Headlines” or “FoxSports Last News”.

      Thanks for this code wpbeginner

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.