0

I have a nav which I would like to detect if an li should have a class of active or not.

I usually do this for a normal page like this:

    <li <?php if ( is_page('about')) { echo ' class="active"'; } ?>>
                            <a href="<?php bloginfo('url'); ?>/about">About</a>
                        </li>

However I'm doing this on a taxonomy page and I would like to detect the name of the taxonomy term. So I have 4 terms, design, illustration, motion and photography.

How would I go about adding a class to the li of the active taxonomy term?

Here is what I have so far but its wrong:

<li <?php if ( is_taxonomy('illustration')) { echo ' class="active"'; } ?>><a href="<?php echo site_url(); ?> /talcat/illustration">Illustration</a></li>

Update:

I have changed is_taxonomy to is_tax and then defining my taxonomy name and term. However this still isnt working. Here is my update coded:

<li <?php if ( is_tax( $Talcat, $illustration)) { echo ' class="active"'; } ?>>
0

You should go and read Debugging in Wordpress, as this problem could be easily solved with debug set to true

is_taxonomy() was depreciated in version 3.0 already, and has been replaced with is_tax( $taxonomy, $term )

You'll just need to specifiy your taxonomy and term in the parameters and you should be good to go

| improve this answer | |
  • Thank you for your answer, I have updated my question above as this still didnt seem to work. – user2648610 Jul 24 '14 at 11:27
  • O, you are the talcat man. As said in your previous question I answered, don't use capital letters in your name. Also $Talcat, $illustration should be 'Talcat', 'illustration'. You should really set debug to true in wp-config.php :-) – Pieter Goosen Jul 24 '14 at 11:33

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.