Using WordPress ‘feed_link’ PHP filter

The feed_link WordPress PHP filter allows you to modify the feed type permalink.

Usage

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

Parameters

  • $output (string) – The feed permalink.
  • $feed (string) – The feed type. Possible values include ‘rss2’, ‘atom’, or an empty string for the default feed type.

More information

See WordPress Developer Resources: feed_link

Examples

Change the feed permalink for a specific feed type.

add_filter('feed_link', 'change_feed_permalink', 10, 2);
function change_feed_permalink($output, $feed) {
    if ($feed == 'rss2') {
        return 'https://yourdomain.com/custom-rss2-feed-url';
    }
    return $output;
}

Add UTM parameters to feed links for tracking purposes.

add_filter('feed_link', 'add_utm_parameters', 10, 2);
function add_utm_parameters($output, $feed) {
    return $output . '?utm_source=feed&utm_medium=' . $feed;
}

Redirect your feed links to Feedburner for better management and tracking.

add_filter('feed_link', 'redirect_to_feedburner', 10, 2);
function redirect_to_feedburner($output, $feed) {
    return 'http://feeds.feedburner.com/YourFeedburnerID';
}

Modify Default Feed Type

Change the default feed type to ‘atom’.

add_filter('feed_link', 'modify_default_feed_type', 10, 2);
function modify_default_feed_type($output, $feed) {
    if ($feed == '') {
        $feed = 'atom';
        $output = get_feed_link($feed);
    }
    return $output;
}

Remove all feed links from your website.

add_filter('feed_link', 'remove_feed_links', 10, 2);
function remove_feed_links($output, $feed) {
    return '';
}