Tulip Media

Entrepreneurial thoughts

Create a new personalized RSS feed in WordPress

 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);

$lastpost = $numposts – 1;

header(“Content-Type: application/rss+xml; charset=UTF-8”);
echo ' ';
?>
<channel>
Your title
Your URL
your description
fr-fr
post_date_gmt) ); ?>
post_date_gmt) ); ?>
Your mail
<?php foreach ($posts as $post) { ?>
<item>
<?php echo get_the_title($post->ID); ?>
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!

 

My latest tweets

New shorts on Blooness 👉 Vitality, longevity, weight loss: the ultimate guide to proteins in the keto-Mediterranean diet is online on Blooness. https://buff.ly/3xxNvpj
https://buff.ly/4cG2GM4

New shorts on Blooness 👉 The new premium content comes out in 48 hours, and what content! This will be the most comprehensive guide on the amount of protein to consume on a keto-Mediterranean diet. See you soon !
https://buff.ly/3L2KbFP

New Post: Combo, the best solution to put an end to the headache of scheduling and HR management https://buff.ly/4eE6JtT

Load more

Don't miss business advice by email

No spam, just an email when new content is published.

7 Responses

  1. No worries, I’ll take this opportunity to point out that there remains a “yoast_rss_date” function in the one you give 😉

  2. Hello, thank you for this little article, I have a little problem, I have an error on the first line when I try to load the created page:

    Parse error: syntax error, unexpected T_VARIABLE

    I looked for solutions, but I still haven't found anything, do you know where this could come from?
    thanks in advance

Leave a Reply

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

en_USEN