7

Active Only Tag Display in WordPress

 3 years ago
source link: https://nixmash.com/on-wordpress/active-only-tag-display-in-wordpress/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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.

activetags1009a.png

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

activetags1009b.png

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.

activetags1009c.png

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.

activetags1009d.png

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.

activetags1009e.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK