The get_category_rss_link() WordPress PHP function prints or returns a link to a category’s RSS2 feed.
Usage
echo get_category_rss_link($display, $cat_id);
Parameters
$display
(bool): Optional. Whether to display or return the link. Default:false
.$cat_id
(int): Optional. The category ID for which to get the RSS link. Default:1
.
More information
See WordPress Developer Resources: get_category_rss_link()
Examples
Display RSS link for a specific category
In this example, we display the RSS link for the category with ID 4
.
echo get_category_rss_link(true, 4);
Get RSS link for a specific category and assign it to a variable
In this example, we get the RSS link for the category with ID 7
and assign it to a variable $rss_link
.
$rss_link = get_category_rss_link(false, 7);
Display RSS link for the current category in a category archive template
In this example, we display the RSS link for the current category in a category archive template using get_queried_object_id()
.
echo get_category_rss_link(true, get_queried_object_id());
Display all categories’ RSS links
In this example, we loop through all categories and display their respective RSS links.
$categories = get_categories(); foreach ($categories as $category) { echo get_category_rss_link(true, $category->term_id); }
Create an array of RSS links for all categories
In this example, we create an array containing the RSS links of all categories.
$categories = get_categories(); $rss_links = array(); foreach ($categories as $category) { $rss_links[] = get_category_rss_link(false, $category->term_id); }