Restricting WordPress Tags by Category

Have you ever needed to display category tags? If you want to only display the tags associated with a specific category, unfortunately the built-in WordPress functions will not suffice. Why such basic functionality has to this day not been added to WordPress is beyond me.

Thankfully, after much frustration and research, I have found a working solution using a plugin called Sensitive Tag Cloud. You can visit the plugin home page, or download the plugin from the official WordPress Plugin page.

Once you have installed and activated the plugin, access the configuration page (Appearance -> SensitiveTagCloud) and ensure that the "Restricted to current category" option is enabled.

Now to display the tags for a specific category when you're browsing that category, edit the archives.php file for your theme and find the section related to browsing by category:

          <?php /* If this is a category archive */ if (is_category()) { ?>
                <h1 class="pagetitle">Category: <?php single_cat_title(); ?></h1>

Now, right below that second line, insert the following function to call SensitiveTagCloud:

  if( function_exists("stc_widget") )

You can also wrap the function in a div if you want to style it. Here's how my archive.php file looks now (minus the unrelated sections of code):

          <?php /* If this is a category archive */ if (is_category()) { ?>
                <h1 class="pagetitle">Browsing: <?php single_cat_title(); ?></h1>
<div style="background:#EAF3F3 none repeat scroll 0 0; border: 1px solid #D0D8D8; padding: 20px;">
  if( function_exists("stc_widget") )

And with those changes, here's how my Category pages now look:

This allows for browsing the tags associated with a specific category, while eliminating irrelevant tags. I write on a variety of topics, so there are a lot of tags that are unrelated or that would be out of context. For example, the "Blogging" tag in the Personal Development category would likely mean something different than the same tag in the Technology category (the latter having more to do with technical things like this article on WordPress).

Write a Comment


  1. hi

    i read your useful post on sensitive tag cloud.
    i am wandering if you also know a plugin thar enables to associate automatically a specific tag to a specific category so that all posts in thar category will have the tag.



    • Hi Stefano,

      You might be be able to use the Category to Tags converter by WordPress. To install it, go to Dashboard -> Tools -> Import -> Categories and Tags Converter. That tool will allow you to selectively convert categories into tags. Using that tool, you could convert a category into a tag (so that all posts with that category now have that tag), recreate the category with the same name, and then mass-edit all posts with that tag and add them back into a category with the same name (so that all your posts have a tag and a category with the same name).

      Otherwise, you might want to try a plugin like Simple Tags that lets you mass-edit lots of posts at once and add tags that way.

      Hope this helps!