Adding active/current class to get_terms list

Question

I have a list of terms I’m displaying using “get_terms”. Each term is linked so if the user clicks it, they go to the term archive page.

 <?php $terms = get_terms('category');t
 echo '<ul>';
 foreach ($terms as $term) {
 echo '<li><a href="'.get_term_link($term).'">'.$term->name.'</a></li>';
 }
 echo '</ul>';
 ?>

However, I would like to know if there’s a way to add an “active” class to each term link if user goes to the term archive page.

Thanks a lot for your help,

0
, , Johann 3 years 2020-04-03T08:50:55-05:00 0 Answers 153 views 0

Leave an answer

Browse
Browse