Custom Menu Classes
-
I’m trying to add a custom class to the menus that are generated. I am adding a custom field to each page/post and I need the value to be in the class. Here is my code.
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2); function special_nav_class($classes, $item){ $color = get_post_custom($item->object_id, 'color', TRUE); echo "[".$item->object_id."][".$color."]"; if($color == "green"){ $classes[] = 'green'; }else if($color == "yellow"){ $classes[] = 'yellow'; }else{ $classes[] = 'pink'; } return $classes; }
The part the does the echo is spitting out the correct ID but the $color is always an array. I can’t figure out what is going wrong.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Menu Classes’ is closed to new replies.