How to Add RSS Subscription for Tags and Custom Taxonomy Archives


Recently on WPBeginner, we wrote an article about how to allow users to subscribe to categories in WordPress. We briefly mentioned that WordPress offers RSS subscription for all taxonomies: categories, tags, and custom taxonomies. In this article, we will show you how to add RSS subscription for tags and custom taxonomy archives.

Similar to categories, each custom taxonomy has it’s own feed URL. All you have to do is add /feed/ at the end of the URL. For example:


Lets take a look at how to add the RSS subscription link on tags and custom taxonomy archives.

Adding RSS Subscription Link on Tag Archives

First thing you need to do is go inside your theme’s folder and find the file called tag.php. If you don’t see tag.php, then look for archive.php. If you don’t see either of those, then there is a strong chance that you are using a WordPress theme framework, and this article will not be as helpful for you.

Now if your theme has a tag.php file, then simply add the following code right before the loop.

  $tag_id = get_query_var('tag_id');    echo '<div class="tag-feed"><p><a href="' . get_tag_feed_link( $tag_id) . '" title="Subscribe to this tag" rel="nofollow">Subscribe</a></p></div>';    ?>  

If your does not have a tag.php file, but it has an archive.php file, then create a new file called tag.php and paste all the code from archive.php in it. Once you are done, then paste the above code in it.

In the code above, we first retrieved the tag ID and then used it to get tag feed link. To add image icons simply replace Subscribe text with an image tag just like we did for categories. Here is how it looked on our test website.

Adding a Subscribe link to Tag Archives

We can do the same thing for custom taxonomy archives.

Adding RSS Subscription Link on Custom Taxonomy Archives

WordPress allows you to add custom taxonomies to go beyond the default categories and tags (Tutorial: how to create custom taxonomies). The process of adding a RSS subscription link on custom taxonomy archives is very similar.

Go inside your theme’s folder and look for a file named as taxonomy-{taxonomy-name}.php (for ex: taxonomy-topics.php if your custom taxonomy is called topics). If you don’t have a custom taxonomy template, then create a new file. Copy and paste the content of your archive.php file into this new file. Once you are done, then paste the following code above the loop:

  <?php    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );    echo '<div class="topic-feed"><p><a href="' . get_term_feed_link($term->term_id, topics, $feed) . '" title="Subscribe to this topic" rel="nofollow">Subscribe</a></p></div>';    ?>  

We hope that you find this article useful in adding RSS feed links to your tags and custom taxonomy archive pages. If you have any questions or suggestions, then please let us know by leaving a comment below.

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.