I am using the following snippet in order to list the terms of a custom taxonomy term I've created called "type".

    $taxonomy = 'type';
    $tax_terms = get_terms($taxonomy);


    foreach ($tax_terms as $tax_term) {
    echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';


The code list all the terms and if I click one of the terms, I get to the archives page, which is great. The thing is that I've noticed that there is no "active" trail class in the active term Wordpress is displaying the info.

So if I am at the restaurant terms page, the related li doesn't show as active.


    <li><a href="http://example.com/stores/type/pharmacies/" >Pharmacies</a></li>
    <li><a href="http://example.com/stores/type/restaurants/">Restaurants</a></li>        


Any idea on how I could add this class (for CSS styling purposes).

Thanks a lot for your help.


Maybe better to use wp_list_catergories.. codex: wp list categories

$args = array(
  'taxonomy'     => 'type',
  'orderby'      => 'name',
  'show_count'   => false,
  'pad_counts'   => false,
  'hierarchical' => true,
  'title_li'     => ''

    <?php wp_list_categories( $args ); ?>

and add to css:

    background-color: #d86f08;
| improve this answer | |
  • This is perfect! – Johann Sep 5 '16 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.