WordPress.org

Ready to get started?Download WordPress

Forums

Class based on nav item title not working (1 post)

  1. everrrettt
    Member
    Posted 5 months ago #

    Hi,

    I am coding a custom theme. I'd like to add a special class to the
    <li> tags based on each's title but the $items variable/parameter for nav_menu_css_class returns empty (var_dump($items) returns NULL).

    Hence 'title_' is all that's returned in the following function:

    function filter_nav_item_css_attributes($classes, $item)
    {
        if(is_array($classes)){
            $classes = array_intersect($classes, array('current-menu-item'));
            array_push($classes,'title_'.$item->title);
            return $classes;
        } else {
            return ' ';
        }
    }

Reply

You must log in to post.

About this Topic