Using WordPress ‘author_feed_link’ PHP filter

The author_feed_link WordPress PHP filter allows you to modify the author feed link.

Usage

add_filter('author_feed_link', 'your_custom_function', 10, 2);
function your_custom_function($link, $feed) {
    // your custom code here
    return $link;
}

Parameters

  • $link (string) – The author feed link.
  • $feed (string) – Feed type. Possible values include ‘rss2’, ‘atom’.

More information

See WordPress Developer Resources: author_feed_link

Examples

In this example, we will change the author feed link to point to a custom domain.

add_filter('author_feed_link', 'change_author_feed_link', 10, 2);
function change_author_feed_link($link, $feed) {
    $custom_domain = 'https://customdomain.com';
    $link = str_replace(home_url(), $custom_domain, $link);
    return $link;
}

In this example, we add a tracking parameter to the author feed link.

add_filter('author_feed_link', 'add_tracking_parameter', 10, 2);
function add_tracking_parameter($link, $feed) {
    $link = add_query_arg('utm_source', 'author_feed', $link);
    return $link;
}

Changing the feed type for author feeds

In this example, we change the feed type for author feeds to ‘atom’.

add_filter('author_feed_link', 'change_feed_type', 10, 2);
function change_feed_type($link, $feed) {
    $link = str_replace('?feed=' . $feed, '?feed=atom', $link);
    return $link;
}

In this example, we remove the author’s name from the author feed link.

add_filter('author_feed_link', 'remove_author_name', 10, 2);
function remove_author_name($link, $feed) {
    $link = preg_replace('/\/author\/[^\/]+\//', '/', $link);
    return $link;
}

In this example, we redirect all author feed links to a static page.

add_filter('author_feed_link', 'redirect_author_feed', 10, 2);
function redirect_author_feed($link, $feed) {
    $static_page_link = home_url('/static-page/');
    return $static_page_link;
}