Active Only Tag Display in WordPress

In today’s Series Twenty Seventeen post we’re going to clean up the Tag Cloud to display only the tags we want to display. I’ve been blogging and coding for years and many of the tags don’t represent my current interests. At all.

You might call this a Starter Approach to displaying only Active Post Tags in WordPress. Quick and Dirty is a description that would probably fit as well. On the other hand there are only a few lines of code required to achieve our goal of a cleaner Tag Cloud, and I think that’s pretty cool.

First of all, here is our Tag Cloud starting point displaying the top 50 tags.

Where we want to go, with only the cooler, trendy tech I’m currently doing. haha.

Starting in the Database

To get started we’re going to take advantage of a neglected WordPress feature called Term Groups. In our database wp_terms table is a column named term_group. This is our Active Tag indicator, where “1” is active and “0” is a tag we don’t want to see any longer.

Querying it up

We’re going to commit a serious sin at this point (I told you it was quick and dirty.) We’re going to add a couple of lines to a WordPress Core Class: class-wp-term-query.php. It’s either that or we duplicate several WordPress classes in our Child Theme. We’re going to check if the argument nixmash_active_only has been passed to the query. If it has, we’ll update the WP Query SQL accordingly. With this approach we limit the tags retrieved to only those instances when we want it and will still retrieve ALL tags in administration and elsewhere.

Passing the Argument

All that is left to do now is to pass the argument to our Tag Cloud, which we’ll do in our Child Theme functions.php.