Site logo

Archived topic

Navigation list class

3 replies · Started by Jean Paiva on May 14, 2015

Viewing posts 1–4 of 4

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?

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 :)

Thank you Tom, I never used this!

No problem! :)

This archived topic is closed to new replies.