How to Filter WordPress Categories from the_category()


On this blog, I have shared various WordPress tips and hacks in past. If you are new to WordPress, I recommend you to read the collection of WordPress tutorials. This post is the addition to a new WordPress topic in that collection. This is another useful post if you are looking to learn WordPress and its development.

There could be various reasons for which you need to print post categories. Most common use it to show all the categories of a post in the blog post. In WordPress, the_category() function is used to display all categories of a specific post. It automatically prints all categories associated with a post. You can also select a separator for printed categories by passing in the function. If you want a comma separated, use the code added below:

But sometimes, you do not want to display all posts. A Few days back, I had the same requirement when I want to hide a specific category from posts. There is no rocket science int his and I achieved that by adding a filter to the_category() function. I found this useful code on This code works fine and you can filter one or more categories. See in the code, it added a filter for categories ‘Mac and ‘Windows’. You can change it as per your own requirement.

Also see: vs

Add this code in the function.php of your theme or create a site-wide plugin to make this code universal.

If you have similar kind of need, you can use this code on your website. You can add filters for as many WordPress category as you want.


Try this code and see if it works fine for you. I recommend you to create a site-wide plugin. By doing this, you will make this code universal. If you edit the functions.php, it will be theme dependent and you will have to put that again if you decide to change the theme later.


Written by Deepanker

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Leave a Reply

Your email address will not be published. Required fields are marked *


send whatsapp messages to a contact with Google Now

How to send WhatsApp messages to a contact with Google Now voice commands


Why should you hide your phone number on Facebook and how to do this?