Would you like to allow visitors to your WordPress site to subscribe to individual categories?
When you offer a separate RSS feed for each category, your visitors can subscribe to the topics they are most interested in.
In this article, we’ll show you how to allow users to subscribe to individual categories in WordPress.
Why Allow Users to Subscribe to Categories in WordPress?
When you start a WordPress blog, you can use use categories to group your blog posts into different sections to help your readers find the content they’re most interested in.
For example, a news website might have categories for their articles filed under News, Opinion, Weather, and Sports.
You might also want to allow your visitors to subscribe to certain categories. That way, they will be notified by RSS or email when you publish new blog posts that they may be interested in.
Luckily, WordPress automatically creates an RSS feed for each category on your site by adding /feed/
at the end of the category page URL.
For instance, if you had a category called ‘News’ with a URL like this:
https://example.com/category/news/
Then its RSS feed would be located at the following URL:
https://example.com/category/news/feed/
But most of your visitors won’t know how to find and subscribe to these feeds. Let’s have a look at how to make it easy for users to subscribe to your WordPress categories.
Adding RSS Subscription Link on Category Pages
We’ll start by adding a simple RSS subscription link to your category pages.
To do this, you need to add code to your website files, and we don’t recommend this for beginners. If you haven’t done this before, then see our guide on how to paste code snippets from the web into WordPress.
The first thing you need to do is go inside your theme’s folder and find the file category.php
. If you don’t see category.php, then look for archive.php
.
If you don’t see either of those, then it’s likely that you are using a WordPress theme framework, and this article will not be as helpful for you.
Now, if your theme has a category.php file, then simply add the following code wherever you want to display the subscription link. We would recommend adding it right before the loop.
<?php
$category = get_category( get_query_var('cat') );
if ( ! empty( $category ) )
echo '<div class="category-feed"><p><a href="' . get_category_feed_link( $category->cat_ID ) . '" title="Subscribe to this category" rel="nofollow">Subscribe</a></p></div>';
?>
If your theme has an archive.php file but does not have a category.php file, then you need to create a new file called category.php and paste all the code from archive.php into it. Once you are done, then paste the above code into it.
Once you’ve added the code snippet, you will be able to see a subscribe link on your category archive page like so:
This code simply adds a link with the anchor text ‘Subscribe’ to the template. You can get fancy by adding an RSS icon instead of text if you prefer. All you have to do is replace the ‘Subscribe’ text with an image URL like so:
<img src="http://example.com/location/to/rss/icon.png" width="48" height="48" alt="Subscribe">
An example subscription icon would look like this:
Adding Other Subscription Options for Categories in WordPress
Most of your visitors who use an RSS reader will already have installed the service’s browser extension for easily adding new feeds. But it can never hurt to add familiar icons to ease the process.
For the sake of example, we will add buttons for two popular web based RSS reader apps, Feedly and Inoreader. You can use the same technique to add other services if you like.
Below is the sample code that you would need to add to your theme’s category.php
file:
<?php
$category = get_category( get_query_var('cat') );
if ( ! empty( $category ) )
echo '<div class="category-feed"><p>Subcribe via: <a href="' . get_category_feed_link( $category->cat_ID ) . '" title="Subscribe to this category" rel="nofollow"><img src="http://example.com/location/to/rss/icon.png" width="32" height="32" alt="Subscribe" /></a>
<a href="http://www.feedly.com/i/subscription/feed/' . get_category_feed_link( $category->cat_ID ) . '" title="Subscribe via Feedly" rel="nofollow"><img src="http://example.com/location/to/feedly/icon.png" width="32" height="32" alt="Subscribe" /></a>
<a href="https://www.inoreader.com/?add_feed=' . get_category_feed_link( $category->cat_ID ) . '" title="Subscribe via Inoreader" rel="nofollow"><img src="http://example.com/location/to/inoreader/icon.png" width="32" height="32" alt="Subscribe" /></a>
</p></div>';
?>
As you can see, we have modified the category feed links for the last two icons. The first icon still points to your original RSS feed, but the second and third icon takes the users to Feedly and Inoreader, so they can subscribe to the category feed.
This is how it looks on our test site:
Adding Email Subscription for Categories in WordPress
Many users are not familiar with RSS and will feel more comfortable with an email subscription to your website.
To add email subscription for categories, you would need to utilize a third-party email marketing service. We recommend using something like Constant Contact or Sendinblue because they offer a feature called RSS to Email.
Once you choose an email marketing service, you need to create an email list and set up an email campaign.
To collect subscribers, we recommend using OptinMonster to build newsletter signup forms.
You can use it to create opt-in forms and easily add category check boxes without writing any code.
After that, you can follow our step by step guide on how to notify subscribers of new posts.
The difference is that you will have to create an RSS to Email campaign and group for each individual category. This is why it is very important that you are using categories the right way.
We hope this tutorial helped you learn how to allow users to subscribe to categories in WordPress.
You may also want to learn how to improve your website’s SEO, or check out our list of 30 proven ways to make money blogging with WordPress.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Sina says
Hi, What about if we want to have our subscribe feature by sending push notification in user browser?
Is it any plugin to do this, like MailChimp for e-mail?
WPBeginner Support says
For push notifications, you would want to take a look at our guide below:
https://www.wpbeginner.com/wp-tutorials/how-to-add-web-push-notification-to-your-wordpress-site/
Admin
Devesh Pal says
First of all, huge fan of your site, very informative, thanks for your service again!
Situation with me is my website has lets say 5 categories in total and the requirement is to display them all, now user can subscribe to any of 5 categories that he/she wish to.
What I have done so far, I have created a subscribe option for all my blogs using feeds but not specific to categories. Can you please help me in the same! Please do reply!
Many thanks for your support so far and in advance!
WPBeginner Support says
Hi Davesh,
Each category on your blog has its own RSS feed too. You can use that RSS feed and create a subscribe option just like you did for your main blog feeds. Please check out the article above for more details.
Admin
Devesh says
Okay!
So can I merge all category’s feed and display only one subscribe input which can show options for selecting either one or more/all categories?
WPBeginner Support says
Hi Devesh,
Yes. Many email services allow you to create multiple RSS to Email campaigns. You can create one for each of your category and then create a form that allows users to choose which lists they want to subscribe to.
subhash says
can you explain how to show categories
roman says
Is there a way for user to manage his subscriptions? Smth like a page or widget with all checkboxes where he could unsubscribe or subscribe to other category?
WPBeginner Staff says
Yes you can but you will have to modify the code for tags.
Kath Rowling says
can you subscribe to certain tags instead of categories?
Ahmed says
Is there a way I can make something like reddit where you subscribe to categories and view them all in a separate page?
Karen says
Hi, I’m building a site for a non profit group and they want a “back office” page/area just for committee/coordinators, so they are given a login in and password to access documents, photos forms etc – not a subscriber type of function. Can you help? cheers karen
Brenda says
Is there any way to do this with custom taxonomies?
WPBeginner Support says
Yes the basic instructions are the same, use
get_term_feed_link( $term_id, $taxonomy = 'customtaxonomyname', $feed = 'rss2' )
instead ofget_category_feed_link()
function.Admin
Swapnali says
Hieee,
This tutorial is awesome… Thanks..
Was finding very difficult to get category subscription for users. Find your tutorial and work was done in just few minutes. Thanks once again.
I want to ask one thing I am using free mailchimp, does it will cretae any problem?
Kimberly says
Nice tutorial, thanks so much.
Marc A. Flego says
First off, I absolutely love this website! Second, I have a question… What if you want to display these very same category subscribe links on your main blog page or even on a single blog post?
I assumed that it would consist of the same code being integrated into blog.php and single.php but that’s not the case – the links appear, but they do not direct correctly when clicked.
Anyone else tried this?
Editorial Staff says
Hey Marc,
The easiest solution would be to use your category URL/feed/ manually. On other pages, $category variable is not available by default. Also wp_list_categories function has the option to display all categories with feed links.
http://codex.wordpress.org/Template_Tags/wp_list_categories
Admin
Marc A. Flego says
Hmm, so there’s no variable category feed URL which can be linked to different blog posts? I would have thought that to be a fairly basic function in WordPress. If a blog post can display a category tag beside it, why can it not display a link to that feed on the same page? Maybe I’m missing something…
Badar ul islam says
This tutorial is super duper useful for people having alot of categories in their blog or website especially having more then 1 niche in their website.
Tuan Vo says
Awesome!!! Very very very very useful post
Zach Smith says
this was actually informative – not like most of what i see online. sharing