How to Create a Custom RSS Feed for a WordPress Site
Use the add_feed() function to register a custom feed in functions.php; 2. Create a feed-custom.php template file and customize query parameters such as classification, author or custom fields; 3. Refresh permalinks to refresh rewrite rules; 4. Optionally use plug-ins to simplify the process; 5. Test feed correctness through browsers and verification tools to ensure that the content, links and dates are correct and not affected by cache, and ultimately achieve full control of WordPress custom RSS feed.

Creating a custom RSS feed for your WordPress site gives you control over what content is included, how it's formatted, and who it's for—whether it's for newsletters, third-party tools, or niche content distribution. While WordPress comes with built-in RSS feeds (like /feed ), a custom feed lets you filter posts by category, author, custom post type, or even specific metadata.

Here's how to create a custom RSS feed in WordPress:
1. Create a Custom Feed Template
WordPress uses the add_feed() function to register new feed types. You'll start by adding a new feed slug and callback function in your theme's functions.php file (or in a custom plugin):

function custom_rss_feed() {
add_feed('custom', 'custom_rss_template');
}
add_action('init', 'custom_rss_feed'); This creates a new feed accessible at yoursite.com/feed/custom/ .
Next, create the template file that generates the feed content. In your theme folder, create a file named feed-custom.php . You can copy the structure from wp-includes/feed-rss2.php and customize it.
Example feed-custom.php :
<?php
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>';
$more = 1;
// Query for specific content (eg, only posts in "news" category)
$args = array(
'post_type' => 'post',
'category_name' => 'news', // Change to your category slug
'posts_per_page' => 10
);
query_posts($args);
?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Custom News Feed</title>
<link><?php bloginfo_rss('url') ?></link>
<description>Latest news from our site</description>
<pubDate><?php echo mysql2date('r', get_post_time('Ymd H:i:s', true), false); ?></pubDate>
<generator>WordPress</generator>
<?php while (have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss() ?></title>
<link><?php the_permalink_rss() ?></link>
<pubDate><?php echo mysql2date('r', get_post_time('Ymd H:i:s', true), false); ?></pubDate>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
<content:encoded><![CDATA[<?php the_content_feed('rss2'); ?>]]></content:encoded>
</item>
<?php endwhile; ?>
</channel>
</rss> Now visit yoursite.com/feed/custom/ to see your filtered RSS feed.
2. Customize the Feed Query
You can modify the $args array in feed-custom.php to include:
- Specific custom post types (
'post_type' => 'product') - Posts by a certain author (
'author_name' => 'john') - Posts with a custom field (using
meta_query) - A different number of items (
'posts_per_page' => 20)
For example, to include only posts with a custom field featured set to yes :
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
'meta_query' => array(
array(
'key' => 'featured',
'value' => 'yes',
'compare' => '='
)
)
);3. Flush Rewrite Rules
After adding the feed, you may need to refresh WordPress permalinks:
- Go to Settings > Permalinks in your admin dashboard
- Click “Save Changes” (no need to change anything)
This ensures the new /feed/custom/ endpoint is recognized.
4. Optional: Use a Plugin for Simplicity
If coding isn't your thing, plugins like:
- Feedzy RSS Feeds (for pulling and customizing feeds)
- Custom RSS Feed Plugin (lightweight, no-code feed creation)
- WP RSS Aggregator (with feed customization add-ons)
…can help generate and manage custom feeds without touching code.
But for full control, the manual method is best.
5. Validate and Test Your Feed
Always test your feed:
- Open
yoursite.com/feed/custom/in a browser - Use a validator like //m.sbmmt.com/link/d4180fd599207086faf95544d33a17e0
- Check that content, dates, and links appear correctly
Also, ensure caching plugins aren't breaking the feed output—exclude the feed URL from aggressive caching if needed.
Creating a custom RSS feed in WordPress isn't hard once you know how. With add_feed() and a template file, you can serve tailored content to subscribers, apps, or services exactly how you want. Just remember to keep your feed-custom.php file backed up if you're using a theme that updates.
Basically, it's just a filtered view of your content wrapped in RSS XML—and you've got full control over both.
The above is the detailed content of How to Create a Custom RSS Feed for a WordPress Site. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20518
7
13631
4
Consuming and Displaying an RSS Feed in a React Application
Sep 23, 2025 am 04:08 AM
To add RSSfeed to React applications, you need to resolve CORS restrictions and parse XML data through a server-side proxy. The specific steps are as follows: 1. Use CORS agent (development stage) or create server functions (production environment) to obtain RSSfeed; 2. Use DOMParser to convert XML into JavaScript objects; 3. Request this interface in the React component to obtain parsed JSON data; 4. Render the data to display the title, link, date and description, and safely process the HTML content; 5. It is recommended to add load status, error handling, entry restrictions and server-side cache to optimize the experience. The ultimate implementation integrates external content without a third-party API.
Creating Dynamic RSS Feeds with Server-Side Logic
Jul 28, 2025 am 01:27 AM
DynamicRSSfeedsaregeneratedontheflyusingserver-sidelogictodeliverpersonalized,real-timecontent.1.Unlikestaticfeeds,dynamicfeedspullfreshdatafromdatabasesorAPIswitheachrequest,enablingup-to-date,user-specificcontent.2.Setupaserverendpoint(e.g.,/feed/r
How to Create a Custom RSS Feed for a WordPress Site
Sep 16, 2025 am 12:36 AM
Use the add_feed() function to register a custom feed in functions.php; 2. Create a feed-custom.php template file and customize query parameters such as classification, author or custom fields; 3. Refresh the permalink to refresh the rewrite rules; 4. Optionally use plug-ins to simplify the process; 5. Test the correctness of the feed through the browser and verification tools to ensure that the content, links and dates are correct and not affected by cache, and ultimately achieve full control of WordPress custom RSSfeed.
Integrating RSS Feeds into a WordPress Website without Plugins
Sep 05, 2025 am 03:30 AM
To add RSS feeds in WordPress without plug-ins, 1. Use the built-in fetch_feed() function of WordPress (based on SimplePie) to obtain and parse RSS feeds, ensure that the feed.php file is included, specify the source address, limit the number of entries displayed, and safely output the content; 2. Embed the code into page templates, widgets, or create short codes to achieve flexible calls. It is recommended to define short codes in functions.php to insert them at any location; 3. Optional JavaScript solution, use rss2json and other services to convert RSS to JSON, load them on the front end through FetchAPI, avoid PHP restrictions, but rely on third-party servers
How to Build a Custom RSS Feed for a Content Management System
Jul 30, 2025 am 12:54 AM
UnderstandthatanRSSfeedrequiresarootelementwithversion2.0,acontaining,,,andoneormoreelementseachwith,,,inRFC822format,andoptionally;2.Setupadedicatedendpointlike/feedbycreatingaroutethatoutputsproperlyformattedXMLwiththecorrectContent-Typeheader,esca
Troubleshooting RSS Feed Validation Issues
Aug 06, 2025 am 12:51 AM
TofixRSSfeedvalidationissues,1.ensurewell-formedXMLbyclosingandnestingtagsproperlyandescapingspecialcharactersorusingCDATA;2.validateagainstRSS2.0specsbyincludingrequiredelementslike,,inbothchannelanditems,andusingthecorrectrootelement;3.setproperenc
Building an RSS Feed Reader with JavaScript and the Fetch API
Sep 10, 2025 am 12:41 AM
You can use JavaScript and FetchAPI to build an RSS reader. First, you can obtain RSSXML text through the CORS proxy, then parse it into a DOM structure with DOMParser, then extract the title, link, publishing time and description in the item, and finally render it to the page. 1. Use the RSSURL after fetch to request proxy and get the response JSON data; 2. Extract XML strings from data.contents and parse them into XML documents with DOMParser; 3. Query all item nodes and extract the required fields to store them into an array; 4. Map the data into HTML strings and insert them into the page container; 5. Add loading status and error handling to improve
Creating a PubSubHubbub-enabled RSS feed for real-time updates
Oct 03, 2025 am 03:11 AM
To create an RSSfeed that supports PubSubHubbubbub, you must first make sure that the feed is formatted correctly and publicly accessible, and then add the hub to the channel part of the feed to find that the link points to public hubs such as https://pubsubhubbub.appspot.com; then, when there is a subscription request, the server must be able to handle the GET verification challenge initiated by the hub and complete ownership verification by returning the provided challenge value; then, every time new content is published, a POST request is sent to the hub to notify it to push updates; finally, use tools such as SuperfeedrConsole or PuSHValidator to test the entire process





