Using WordPress ‘get_feed_link()’ PHP function

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 of get_default_feed().

More information

See WordPress Developer Resources: get_feed_link()

Examples

To display the RSS2 feed link for your site, you can use the following code:

echo 'RSS2 Feed: ' . get_feed_link('rss2');

To display the Atom feed link for your site, you can use the following code:

echo 'Atom Feed: ' . get_feed_link('atom');

To display the default feed link for your site, you can use the following code:

echo 'Default Feed: ' . get_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);

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>';