0

I'm trying to add sequential numbers to menu items in increments of one.

So right now where I have the following:

<li class="menu-item menu-item-type-taxonomy menu-item-object-category"></li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category"></li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category"></li>

I would like to have the following:

<li class="menu-item menu-item-type-taxonomy menu-item-object-category 1"></li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category 2"></li>
<li class="menu-item menu-item-type-taxonomy menu-item-object-category 3"></li>

I know how to add sequential numbers with an increment of one to post loops but I'm using a custom menu walker for this menu and I don't know how to do it.

Here is the code that dictates the classes that are added to the menu currently:

$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
$class_names = $class_names ? ' class="' . esc_attr($class_names) .'"' : '';

$output .= $indent . '<li' . $id . $value . $class_names .'>';

Can you tell me how to add sequential numbers to the class values?

  • On a side note, class names shouldn't start with a digit – RiddleMeThis Jan 2 at 14:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.