
Definition
In WordPress, the_category_rss() prints the categories of a post as XML for a feed. Each category becomes one <category> tag.
You only use it when you write your own feed template. On normal pages use the_category().
Syntax
A few ways to call the_category_rss().
<item>
<title><?php the_title_rss(); ?></title>
<?php the_category_rss(); ?>
</item>
| Call | What it does |
|---|
the_category_rss() | Print category tags in the default feed type. |
the_category_rss( 'rdf' ) | Print them as dc:subject tags for an RDF feed. |
the_category_rss( 'atom' ) | Print them in Atom feed format. |
get_the_category_rss() | Return the same text as a string. |
It prints one XML tag for each category and tag of the post. It also includes post tags.
Full declaration
the_category_rss( string $type = null ): void
Parameters
| Parameter | Description |
|---|
$type | string. The feed type: rss, atom, or rdf. Default is the default feed type of the site. |
Return Value
| Return Value | Description |
|---|
| void | Nothing is returned. The XML tags are printed. |
WordPress Examples
Three short examples. Each one shows the code and what it prints.
Example 1 — Categories inside a feed item
Use it inside an item of a custom RSS feed.
<item>
<title><?php the_title_rss(); ?></title>
<?php the_category_rss(); ?>
</item>
<item>
<title>Hello World</title>
<category><![CDATA[News]]></category>
<category><![CDATA[WordPress]]></category>
</item>
How It Works
the_title_rss() prints the title for the feed.the_category_rss() prints one category tag for each category.- Names are wrapped in CDATA.
Example 2 — RDF feed type
Pass rdf for an RDF feed.
<?php the_category_rss( 'rdf' ); ?>
<dc:subject><![CDATA[News]]></dc:subject>
<dc:subject><![CDATA[WordPress]]></dc:subject>
How It Works
- The type
rdf changes the tag name. - RDF feeds use
dc:subject for categories. - The values are the same.
Example 3 — Return the XML
Use get_the_category_rss() to store the text.
<?php
$cats = get_the_category_rss( 'rss' );
echo $cats;
<category><![CDATA[News]]></category>
<category><![CDATA[WordPress]]></category>
How It Works
get_the_category_rss() returns the same XML as a string.- You can check or change it before you print.
- Here we just print it.
Frequently Asked Questions
It prints the categories of a post as XML tags for an RSS feed.
Only in feed templates, inside an item.
Yes. It prints both categories and post tags.
Pass rss, atom, or rdf as the first argument.
Use the_category().
Browse all post functions
Open the functions index for simple guides with examples and FAQs.
Post Functions Index →About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
7 people found this page helpful