Back to Top

How to Parse WordPress RSS Feed?

Parsing a RSS Feed with Wordpress

Nowadays, RSS Feed is commonly used in all sites which provide you the latest news or information of the site.

You must have to take care if you are parsing RSS feeds which are not your own and you have to have permission to use the feed.

Let’s start to understand code

we are going to understand for WordPress so first of all you need to include below file if you are using the custom page.


SimpleXML provides is a simple way of getting an XML element and converts an XML document into a SimpleXMLElement here we will use simpleXML to extract data.

$data = wp_remote_retrieve_body(wp_remote_get($url, array( 'timeout' => 30 ) ));
$dom = new DOMDocument;
if (!$dom) {
  echo 'Error while parsing the document';
$xml = simplexml_import_dom($dom);
$xml_data = $xml->channel->item;

Here,we have used wordpress function wp_remote_retrieve_body which retrieve body from the remote servers and body of the page can be accessed through wp_remote_get/wp_remote_post method in wordpress. Then we have used DOMDocument which represents the object of entire XML document and loadXML which is used to parse an XML string when uses the DOMDocument object.

simplexml_import_dom is uses a node of a DOM document and convert it into a SimpleXML node.It will parse the data received & return it as a SimpleXML Object.

foreach($xml_data as $key => $val) {
 echo $val->title;

By the end, I suggest you to read:

To extract RSS XML feed in PHP
WordPress: To add custom post type into RSS
How to fetch and display a feed in WordPress?

As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (2)

  1. Thank you for this article! I am working on a site that needs this functionality, you are a lifesaver.

  2. Hello 🙂 I am Tommy, it’s my first occasion to commenting anyplace when I read this paragraph I thought I could also create comment due to this brilliant post

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to allow more MIME types in WordPress

Posted on 6 years ago


An Introduction to Kubernetes

Posted on 3 years ago


How to set DirectoryIndex using .htaccess?

Posted on 4 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago