[resolved] Adding css classes to menu items not working (3 posts)

  1. cykeltomte
    Posted 3 years ago #

    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: http://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. ]

  2. cykeltomte
    Posted 3 years ago #

    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.

  3. tarik916
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic