[Resolved] Navigation list class

Home Forums Support [Resolved] Navigation list class

Home Forums Support Navigation list class

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #107997
    Jean Paiva
    Developer

    Hey Tom, I want to add a custom class for the navigation list items, I don’t know, maybe I need to use this funciton?

    <?php
    add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
    function special_nav_class($classes, $item){
         if(is_single() && $item->title == "Blog"){ //Notice you can change the conditional from is_single() and $item->title
                 $classes[] = "special-class";
         }
         return $classes;
    }
    ?>

    From: https://codex.wordpress.org/Function_Reference/wp_nav_menu

    What do you think?

    #108021
    Tom
    Lead Developer
    Lead Developer

    Are you wanting to add custom classes to specific menu items?

    If so, go to “Appearance > Menus” – in the top right corner, click “Screen Options”.

    Then check the “CSS Classes” checkbox.

    Now when you open your menu items, you’ll be able to give them a class.

    Let me know ๐Ÿ™‚

    #108294
    Jean Paiva
    Developer

    Thank you Tom, I never used this!

    #108310
    Tom
    Lead Developer
    Lead Developer

    No problem! ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.