Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

4 Answers 4

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
add comment

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 -->
    </li>
<?php
}
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.