RSS feed link on archives page not working

I made a mess of this in comments, so will start from scratch.

The feed links for archive pages are usually only outputted for browser detection by feed_links_extra().

From looking at its source there is number of different function to get link for the archive pages:

  • get_category_feed_link( $cat_id );
  • get_tag_feed_link( $tag_id );
  • get_term_feed_link( $term_id, $taxonomy ) (this one I found separately, not currently used in automatic feed links).

So catch-all archive feed link that will work for any taxonomy (including categories and terms) can be built like this:

function archive_feed_link() {

    if( is_archive() ) {

        global $wp_query;

        $taxonomy = $wp_query->get_queried_object();

        return get_term_feed_link( $taxonomy->term_id, $taxonomy->taxonomy );
    }
}