Further categorizing your wordpress post!

Tags grouping / categorizing tags

During publishing articles, you may think that using “tags” seems too general. Many times you need more categorized tags, or grouping tags. That way, you can make user easier to find similar tags that consists in the category.

For example: You are publishing an “omelette” recipe post. You need to tag them with ingredients (egg, vegetable oil), utensils (stove, frying pan, spatula) and cooking technique (frying). That way, rather than having bunch of unsorted tags like: egg, vegetable oil, stove, frying pan, spatula, frying; you can sort them better. The example will be shown in the following figure:

Wordpress categorized tag

Fig. 1. WordPress categorized tag

Note: thanks to http://www.epicurious.com/recipes/food/views/classic-omelette-15068 for the recipe.

Moreover, if you do some tweaks in your themes template or via plugin, you can display the categorized tags in tidy manner. It’ll be useful when user wants to browse the category itself. The following picture show an example of categorized tags based on omelette recipe:

Wordpress categorized tag lists

Fig. 2. Categorized tag list

Other useful case is when you are writing a post about notebook, where you can further grouping tags to specify OS, RAM size, HDD size, VGA type, VGA size, etc. So further categorizing tags will be very useful generally.

Tag categorizing is referred by wordpress as “Taxonomy“. However even though fully supported by wordpress, it’s not easy to administrate taxonomy. I suspect that the first intent the taxonomy is developed, it is to be used as specialized themes rather than user customizable. However, with helps from plugins you can easily administrate them.

Plugins required

Types plugin

Types plugin – https://wordpress.org/plugins/types/, is a nice plugin that give you good administrator tools over post types, custom fields and custom taxonomy. Both custom fields and post types are also useful to writing posts, but right now for me the custom taxonomy is the one I need. Here is the example of custom taxonomy page provided by Types plugin:

Wordpress Types plugin custom taxonomies

Fig. 3. Types plugin custom taxonomies page

The administration is rather straightforward here. You only need to create the custom category (ingredient, utensils, cooking technique) then thanks to support of wordpress, all of them will be available in post by itself. The following figures will show how custom taxonomies will show during writing post:

Wordpress custom taxonomy on writing post

Fig. 4. Custom taxonomy on post

As you can see from the Fig. 4 above, in Post menu there are new menu items, each for custom taxonomies defined by user. And during writing post, new box below category will appear where you can fill the custom taxonomies information for the page.

Add actions and filters

Add actions and filters plugin – https://wordpress.org/plugins/add-actions-and-filters/– is a plugin which allow you to add “action hooks” and functions into your wordpress site. Types plugin already help you to maintain custom taxonomies. However, it won’t help you to display the custom taxonomies associated with the post, as shown at Fig. 1. In this case, I use this plugin to show the categorized tag / taxonomies associated with post. I use the following code snippet:

function render_taxonomy($content) {
    $excluded_taxonomies = array(
    $taxonomies = get_taxonomies();
    $post_id = get_the_ID();
    $result = '';

    $result .= '<div class="post_taxonomy">';
    foreach($taxonomies as $taxonomy){
        if(in_array($taxonomy, $excluded_taxonomies) == false)
            $obj_taxonomy = get_taxonomy($taxonomy);
            $result .= get_the_term_list($post_id , $taxonomy, '<strong>' . $obj_taxonomy->label . ': </strong>', ', ');
            $result .= '<br/>';
    $result .= '</div>';
    return $content . $result;


That’s it. With those 2 plugins, your wordpress now has categorized tags.

Showing list of taxonomies

Now that you may want to display the list of taxonomies in one page, as shown under Fig. 2. In this case, I use the following code snippet inside “add actions and filters plugin” to add shortcode. The defined shortcode will render the list of taxonomies defined in your wordpress site. Then, the shortcode can be used in any page / post to instantly change the page / post into taxonomies list.

function render_taxonomies() {
    $excluded_taxonomies = array(
    $taxonomies = get_taxonomies();
    $result = '';
    $result .= '<div class="taxonomies">';
    foreach($taxonomies as $taxonomy){
        if(in_array($taxonomy, $excluded_taxonomies) == false)
            $obj_taxonomy = get_taxonomy($taxonomy);
            $taxonomy_name = $obj_taxonomy->name == 'post_tag' ? 'tag' : $obj_taxonomy->name;
            $result .= '<h2><a name="' . $taxonomy_name . '">' . $obj_taxonomy->label . '</a></h2>';
            $query_taxonomies = array( $taxonomy );

            $args = array(
                'orderby'           => 'name', 
                'order'             => 'ASC',
                'hide_empty'        => true, 
                'exclude'           => array(), 
                'exclude_tree'      => array(), 
                'include'           => array(),
                'number'            => '', 
                'fields'            => 'all', 
                'slug'              => '',
                'parent'            => '',
                'hierarchical'      => true, 
                'child_of'          => 0,
                'childless'         => false,
                'get'               => '', 
                'name__like'        => '',
                'description__like' => '',
                'pad_counts'        => false, 
                'offset'            => '', 
                'search'            => '', 
                'cache_domain'      => 'core'

            $terms = get_terms($query_taxonomies, $args);
            $result .= '<div class="taxonomy"><ul>';
            foreach($terms as $term){
                $result .= '<li>';
                $result .= '<a href="' . get_site_url() . '/' . $taxonomy_name . '/' . $term->name . '">' . $term->name . '</a>';
                $result .= '</li>';
            $result .= '</ul></div>';
    $result .= '</div>';
    return $result;

add_shortcode('render_taxonomies', 'render_taxonomies');

Then to use it, just make a page with [render_taxonomies] as the content.


Further categorizing your wordpress site will enhance navigation experience for user.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s