Assign a Class to the Current “Tag” for Formatting

Essentially what I am hoping to replicate is something like the “current-menu-item” class that is applied to WP Menus.

My client is wanting to use Tags as a sub-nav, and I’ve managed to get the tags for the category output as an unordered list, but now if someone selects the tag “Tag One”, I’d like to have that particular tag to highlight as the currently selected Tag.

It would be extra super cool if this could also work with the output generated by “the_tags” attached to the post as well.

I hope this makes sense, and thanks!

Cheers,
John

1
1

Add something like this to the functions file:

function current_tag($tags) {
    global $wp_query;
    $cid = $wp_query->query_vars['cat'];
    foreach($tags as $tag) {
        // match tagid to $cid
    }
} 
add_filter( 'get_the_tags', 'current_tag');

This won’t work by itself, but it will be a good start for getting the right information to the right place.

Leave a Comment