is_tax() conditional tag not working
-
Hi,
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')
oris_archive('sites')
conditions return true.One of my main menu items (
menu-item-3
below) is a custom taxonomy so instead of using either of the above two methods, I’m usingis_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. I’ve added some dummy text to my custom taxonomy archive template file, and the correct template file is being used for the taxonomy archive page.Below is the code – any ideas about how to solve this would be hugely appreciated.
HTML / PHP
<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> </ul> </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> </ul>
CSS
.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; }
- The topic ‘is_tax() conditional tag not working’ is closed to new replies.