wp nav menu: add attributes to menu items [duplicate]

You can use a Custom Walker to add attributes to the menu items.

Basically, you add a parameter ‘walker’ to the wp_nav_menu() options and call an instance of an enhanced class:

wp_nav_menu(
    array (
        'menu'            => 'main-menu',
        'container'       => FALSE,
        'container_id'    => FALSE,
        'menu_class'      => '',
        'menu_id'         => FALSE,
        'depth'           => 1,
        'walker'          => new Description_Walker
    )
);

The class Description_Walker extends Walker_Nav_Menu and changes the function start_el( &$output, $item, $depth, $args ).

  1. From the Codex:
    http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function

  2. I found this tutorial, you might find it very useful:
    http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output