In this week’s WordPress Wednesday, we’re covering a simple way to exclude categories from
the_category() tag’s output in your themes.
On a recent project, I not only wanted to make sure the ‘Uncategorized’ tag didn’t display; I also needed to hide two additional tags that were doing some heavy-lifting in the background, but didn’t need to be displayed on the site. Unfortunately,
the_category() tag doesn’t have an option to exclude specific categories.
Enter this handy function from the WordPress support forums — just add it to your theme’s
Initially, I did have some issues with this function; after some tinkering around, I realized I needed a separator declared in
the_category() tag, like a comma, dash, etc. In this case, I was using just a space —
the_category(' ') — which wasn’t working, but swapping it out for a non-breaking space did the trick:
Have you run across any WordPress tags are missing options you need?