The get_feed_link() WordPress PHP function retrieves the permalink for the specified feed type.
Usage
get_feed_link( $feed );
Example:
echo get_feed_link('rss2');
Output: https://example.com/feed/rss2
Parameters
$feed
(string) Optional – Feed type. Possible values include ‘rss2’, ‘atom’. Default is the value ofget_default_feed()
.
More information
See WordPress Developer Resources: get_feed_link()
Examples
Display the RSS2 Feed Link
To display the RSS2 feed link for your site, you can use the following code:
echo 'RSS2 Feed: ' . get_feed_link('rss2');
Display the Atom Feed Link
To display the Atom feed link for your site, you can use the following code:
echo 'Atom Feed: ' . get_feed_link('atom');
Display the Default Feed Link
To display the default feed link for your site, you can use the following code:
echo 'Default Feed: ' . get_feed_link();
Create a Custom Feed Link
To create a custom feed link for a specific category, you can use the following code:
$category_id = 1; // Replace with your desired category ID echo 'Custom Category Feed: ' . get_category_feed_link($category_id);
Display Feed Links in an HTML List
To display the feed links in an HTML list, you can use the following code:
echo '<ul>'; echo '<li><a href="' . get_feed_link('rss2') . '">RSS2 Feed</a></li>'; echo '<li><a href="' . get_feed_link('atom') . '">Atom Feed</a></li>'; echo '<li><a href="' . get_feed_link() . '">Default Feed</a></li>'; echo '</ul>';