• Resolved cykeltomte

    (@cykeltomte)


    I’m trying to add specific custom classes to items in my menu by adding the css classes through the wordpress dashboard, but I can’t seem to get it to work. I have added the class .test to style.css, but when applying the class to a menu item through wordpress dashboard no changes can be seen. The menu can be seen here: https://mediastudent.ei.hv.se/~jeau0002/mobil/

    Am I missing something? I use bones_main_nav(); to call the menu, if it has something to do with it.

    [ Please do not bump, it’s not permitted here. ]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter cykeltomte

    (@cykeltomte)

    Solved it by adding this code to functions.php.

    add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
    function special_nav_class($classes, $item){
    	$title = strtolower($item->title);
    	$classes[] = $title;
    	return $classes;
    }

    Not exactly what i had in mind, but it actually works better as it automatically adds the title of the menu item as a class.

    Thanks! This was helpful! I added $title = str_replace(” “,”_”, $title); below the first lowercase command in order to better format the classes.

    Instead of how.can.we.help, it’s how_can_we_help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding css classes to menu items not working’ is closed to new replies.