I have a menu item where a CSS class is added with a 'page_active' class (which visually shows an underline under the relevant item). This is added on certain menu items if the is_page('Latest') or is_archive('sites) conditions return true.

One of my main menu items (menu-item-3) is a custom taxonomy so instead of using either of the above two methods, I'm using is_tax('web') for a custom taxonomy called 'web'. This isn't adding the 'page_active' class though and also the CSS class is still being added to one of the other two items.

Below is the code - any ideas about how to solve this would be hugely appreciated.


.underline.page_active:after {
    content: '';
    position: absolute;
    width: 100%;
    height: 5px;
    background: #a882ff;
    left: 0;
    bottom: -0.39em;
    z-index: -1;

.menu-item-2.underline.page_active:after {
    width: 3.1rem;
    left: 5.7rem;
    z-index: -1;
    bottom: 2rem;


<ul class="nav-menu-items">
    <li class="menu-item menu-item-1"><a class="td nav-link underline <?php if (is_page('Latest')) {echo "page_active";};?>" title="Latest" href="<?php echo esc_url(home_url( '/' ));?>">Latest</a></li>
    <li class="menu-item menu-item-2 underline <?php if (is_archive('sites') || is_tax('graphic-design')){echo "page_active";}; ?>">Design
        <ul class="submenu design-submenu">
            <li class="submenu-item submenu-item-1"><a title="Sites We Like" class="td nav-link" href="<?php echo esc_url(home_url('/sites'));?>">Sites We Like</a></li>
            <li class="submenu-item submenu-item-2"><a title="Graphic Design" class="td nav-link" href="<?php echo esc_url(home_url('/news_categories/graphic-design'));?>">Graphic Design</a></li>
    <li class="menu-item menu-item-3"><a title="Web" class="td nav-link underline <?php if (is_tax('web')){echo "page_active";};?>" href="<?php echo esc_url(home_url('/news_categories/web'));?>">Web</a></li>
    <li class="menu-item menu-item-4"><a title="Marketing" class="td nav-link underline" href="<?php echo esc_url(home_url('/news_categories/marketing'));?>">Marketing</a></li>
  • is_tax only works if you're accessing archive page of web taxonomy. Are you? Commented Feb 21, 2020 at 18:07
  • @CaduDeCastroAlves Hi - yes I am. I have a 'news_catergories' group of taxonomies of which 'web' is one of those. The template file is a 'taxonomy-news_categories.php' and the archive itself does show the 'web' taxonomy correctly.
    – pjk_ok
    Commented Feb 21, 2020 at 18:41
  • If you add global $wp_query and then var_dump($wp_query), you should be able to see if $wp_query->is_tax is properly set. Commented Feb 21, 2020 at 18:44
  • @CaduDeCastroAlves Do I just add that in <?php ?> tags on the taxonomy archive template file? Or in the header.php file where the nav menu is?
    – pjk_ok
    Commented Feb 21, 2020 at 18:53
  • news_categories is "a group of taxonomies"? I'm not sure that makes sense, since a taxonomy is a group of terms... so are you sure? it seems more like with this structure news_categories is the taxonomy and web is actually a term?
    – majick
    Commented Feb 23, 2020 at 2:19

1 Answer 1


I found the solution to this, the is_tax(); method needs two arguments - the taxonomy and the term itself, so it should have been:

is_tax('news_categories', 'web')

Just as an extra point the is_archive('sites') should also have been is_post_type_archive('sites')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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