Function and usage of get_author_feed_link() in wordpress


Answers ( 1 )


    The get_author_feed_link() function in WordPress is designed to retrieve the feed link for a specific author. Here's a detailed explanation of its function and usage:


    • Name: get_author_feed_link
    • Purpose: To retrieve the feed link for all posts by a given author on a WordPress site.


    • This function returns a URL that points to the feed (RSS or Atom) of posts created by a specific author on a WordPress site.
    • It allows for the specification of a particular feed type or defaults to the site's default feed type if none is specified.


    1. $author_id (int, required): This is the unique identifier for the author. You need to pass the author's ID for whom you want to get the feed link.

    2. $feed (string, optional): This parameter specifies the type of feed you want to retrieve. Possible values include:

      • 'rss2': For RSS 2.0 feed.
      • 'atom': For Atom feed.
      • If this parameter is left empty (''), it defaults to the value returned by get_default_feed(), which is the default feed type set in WordPress (usually RSS 2.0).


    • Type: string
    • Description: The function returns a URL string that links to the feed for the author specified by $author_id.

    Sample Usage:

    Example 1: Default Feed for an Author

    $author_id = 5; // Assume 5 is the author ID
    $feed_link = get_author_feed_link($author_id);
    echo 'Feed link for author: ' . $feed_link;

    This example retrieves the default feed link for the author with ID 5.

    Example 2: Specifying Feed Type

    $author_id = 3; // Assume 3 is the author ID
    $feed_type = 'atom'; // Specifying Atom feed
    $feed_link = get_author_feed_link($author_id, $feed_type);
    echo 'Atom feed link for author: ' . $feed_link;

    In this example, the Atom feed link is retrieved for the author with ID 3.


    • This function is useful for creating custom links or widgets on a WordPress site that allow visitors to subscribe to posts by specific authors.
    • It's important to ensure that the author ID passed to the function is valid to avoid broken links.

Leave an answer