WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using.

<?php wp_nav_menu($args); ?>

to get menu from WordPress.

It returns the menus with <ul> and <li> structure.
How can i set class name for every <li> tag uniquely.

share|improve this question
there's a filter you can use to do this: nav_menu_css_class – onetrickpony Jun 23 '11 at 10:57

You can use the CSS class for the menu.
Under "Screen Options", flag "CSS Classes", under "Show Advanced Properties".

Then, for every menu item, you have an additional input that is named "CSS Classes"

share|improve this answer

I think the best solution would be to write your own walker class for it and pass it as an argument, but I must admit that's not too straight forward if you are not too familiar with wordpress development.

I would solve it like this:

$menu_items = wp_get_nav_menu_items('your_menu_slug_or_id');        
$class = '';
$count = count($menu_items);
$i = 0;

foreach ($menu_items as $menu_item) {
    $class = 'item-'.(++$i);
    <li class="<?php echo $class?>">
        <!-- add menu title and url here as you please -->
share|improve this answer

What is the reason for needing custom classes?

WordPress menus include a number of classes on the <li> elements when the function is run and should be everything you need to work with.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.