The get_category_feed_link() WordPress PHP function retrieves the feed link for a category.
Usage
get_category_feed_link($cat, $feed = '');
Parameters
$cat
(int|WP_Term|object) – The ID or category object whose feed link will be retrieved.$feed
(string, Optional) – Feed type. Possible values include ‘rss2’, ‘atom’. Default is the value ofget_default_feed()
.
More information
See WordPress Developer Resources: get_category_feed_link()
Examples
Basic usage
Retrieve the RSS2 feed link for posts in category 2.
echo get_category_feed_link(2, '');
Display RSS link automatically for categories
Display an RSS link automatically when viewing a category. Insert this code on the category.php or archive.php page template.
if (is_category()) { $category = get_category(get_query_var('cat')); if (!empty($category)) { echo '<div class="category-feed"><a href="' . esc_url(get_category_feed_link($category->cat_ID)) . '" title="' . sprintf(esc_attr__('Subscribe to this category', 'textdomain'), $category->name) . '" rel="nofollow">' . __('Subscribe!', 'txtdomain') . '</a></div>'; } }
Retrieve Atom feed link
Retrieve the Atom feed link for posts in category 3.
echo get_category_feed_link(3, 'atom');
Get feed link using WP_Term object
Retrieve the feed link using a WP_Term object.
$term = get_term(4, 'category'); echo get_category_feed_link($term);
Get feed link using category object
Retrieve the feed link using a category object.
$category_obj = get_category(5); echo get_category_feed_link($category_obj);