Here is a very useful piece of code that will allow you to create a new RSS feed in WordPress.
Indeed, we sometimes need to provide an RSS feed independent of the native feed. For this, there is a piece of code that I discovered on Yoast!
1) Create a new page template called pagerss.php
Start from a blank page in Notepad and insert the following code, before uploading it to your theme folder:
<?php
/*
Template Name: Custom Feed
*/
$numposts = 10;
function custom_rss_date($timestamp = null) {
$timestamp = ($timestamp==null) ? time(): $timestamp;
echo date(DATE_RSS, $timestamp);
}
$posts = query_posts('showposts='.$numposts);
Fan of the WordPress ecosystem? Discover the best of my articles on WordPress as well as my WordPress extensions to make your site shine!
$lastpost = $numposts – 1;
header(“Content-Type: application/rss+xml; charset=UTF-8”);
echo ' ';
?>
<channel>
Your URL
your description
fr-fr
post_date_gmt) ); ?>
post_date_gmt) ); ?>
Your mail
<?php foreach ($posts as $post) { ?>
<item>
ID); ?>
<![CDATA[ post_content; ?>]]>
post_date_gmt) ); ?>
ID); ?>
</item>
<?php } ?>
</channel>
</rss>
You can replace the “Your…” fields with your own fields.
2) Create a new page in WordPress
Publish a new page from your WordPress admin, affiliating it with the “Custom Feed” page template that we have just created above.
3) Launch your published page
Once the page is published, launch it. You should see your new RSS feed!

Leave a Reply