Knowing how to create custom sidebars is great. But sometimes it’s not enough: you might want your custom sidebar to show certain categories only, and exclude others. This post shows you how to exclude categories in WordPress.
I recently had to solve this issue for a client, The Stop Hunter.
The members area has premium content to be downloadable by members only. The sidebar for this area had to show only the categories relevant to the members club.
At the same time, the categories relevant to the members club must not show in the public blog’s sidebar, and the posts filed under the members’ categories must not show in the public blog’s archives and feeds.
So the issue I had to solve was how to exclude specific categories from a sidebar.
How to exclude specific categories from a sidebar
My client would post exclusive membership content in the form of PDFs every week and every month, and wanted an archive of this content.
So the best way would be to create a category for weekly and one for monthly content, and publish the uploads within blog posts. With the wonderful MemberPress plugin that I am using for this site, it is very simple to create a ‘rule’ that protects all content and all posts filed under a given category – so no problem there.
However, out of the box in WordPress the Categories widget automatically shows all of the categories you create, even when they relate to content behind a membership wall. Non-members cannot access the premium content, but they can indeed see it.
This wasn’t what I wanted. I didn’t want the premium content categories to be visible in the public blog sidebar.
But excluding them from the sidebar totally would not work either, because I did want them to appear in the premium content blog sidebar – which, in turn, shouldn’t show the public blog categories. How to separate the two?
Enter the Pro Categories widget.
This handy plugin shows up as a widget in your Appearance> Widgets area. You simply drag the widget on the sidebar where you don’t want the categories to appear, and you enter the IDs of the categories that you don’t want there. Finding the category ID is very simple: on your dashboard, go to Posts> Categories, click on the category name, and the category ID number will appear in your browser address bar, in a format similar to this:
As if by miracle, your sidebar will now only show the categories that you want there, excluding the ones that you don’t.
So in the Pro Categories widget on the premium content pages custom sidebar (created with the Custom Sidebars widget) I excluded the public blog categories by entering their IDs. And in the Pro Categories widget on the public blog pages sidebar I excluded the premium content categories by entering their IDs.
What’s even better, you can use this widget in any other widgetised area you might be using, not just the sidebar.
There is also another plugin that does a good job of excluding categories, and it’s Ultimate Category Excluder. It wasn’t fit for my purpose, however, because it is not selective enough: I didn’t want to exclude the membership categories from ALL sidebars, only from the public blog sidebar. Plus, this plugin hasn’t been updated since 2013, which makes me nervous as this is a client’s site and I cannot risk conflicts or lack of compatibility with the most recent version of WordPress. So if you need a more granular approach, the Pro Categories widget is your answer.
If you find this post useful, you might also like this: