Connect with us

How to create custom RSS feeds in WordPress?


How to create custom RSS feeds in WordPress?

WordPress is giving default RSS feed which is enough for most of the users who want to share their feed with other people (publicly). You can find your default feed url byt writing /feed after your domain url.


In some cases, you want to do little customization like adding thumbnail to RSS feed or adding custom content to existing default feeds. This can be achieved using some plugins as well as with some sort of code. But what if you want more than this ? Are you looking for creating your own Custom RSS feed for your articles ? If yes, here is detailed instructions how to create custom RSS feeds in WordPress.

Before we begin this programming tutorial, please note that the below steps can be skipped, if you use the Echo RSS Generator plugin. It will make things much easier, with one click install and configurations. However, if you wish to create your RSS feed manually, from code, here are the steps needed for this:


First you need to define your new RSS feed in your functions.php file. It will set up a URL so you can give name accordingly.

add_action('init', 'pf_my_own_rss');
function pf_my_own_rss(){
add_feed('customfeed', 'pf_my_own_rss_func');

With the above code, your custom RSS feed url will look like below.


Now you need to write callback function. Write below code in functions.php file. You can either write code directly in below function or make separate file and call the file from here using get_template_part function.

function pf_my_own_rss_func(){
        get_template_part('rss', 'mycustomfeed');


Now you need to create rss-mycustomfeed.php file under your theme directory. Write the below code and change it according to your needs.

 * Template Name: Custom RSS Template - My Own Feeds
$postCount = 25;
$posts = query_posts('showposts=' . $postCount);
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
<rss version="2.0"
        <?php do_action('rss2_ns'); ?>>
        <title><?php bloginfo_rss('name'); ?> - Feed</title>
        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
        <link><?php bloginfo_rss('url') ?></link>
        <description><?php bloginfo_rss('description') ?></description>
        <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
        <language><?php echo get_option('rss_language'); ?></language>
        <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
        <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
        <?php do_action('rss2_head'); ?>
        <?php while(have_posts()) : the_post(); ?>
                        <title><?php the_title_rss(); ?></title>
                        <link><?php the_permalink_rss(); ?></link>
                        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
                        <dc:creator><?php the_author(); ?></dc:creator>
                        <guid isPermaLink="false"><?php the_guid(); ?></guid>
                        <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
                        <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
                        <?php rss_enclosure(); ?>
                        <?php do_action('rss2_item'); ?>
        <?php endwhile; ?>

You can edit it and add custom content whatever you would like to do as per your requirement.


In order to make url works, you need to flush the rewrite rules. You can do it easily by going to Settings -> Permalinks and Click on Save. You are done!


If you want to validate your RSS Feed, you can do using feed validation service, allowing you to validate the resulting feed.

Continue Reading
Click to comment

Leave a Reply

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

More in coding

About Me:

Szabi Kisded

Hey there, I'm Szabi. At 30 years old, I quit my IT job and started my own business and became a full time WordPress plugin developer, blogger and stay-at-home dad. Here I'm documenting my journey earning an online (semi)passive income. Read more

Sign up for my newsletter and get the YouTube Caption Scraper WordPress plugin for free
(worth 29$)!

All My Plugins In A Bundle:

My AutoBlogging Plugins:

My Online Courses:

A Theme I Recommend:

Featured Posts:

To Top