• When I use wp_nav_menu it generates a list with unique ID’s for each li.
    This is fine, but if I want to use the menu in multiple places (ie header and footer) it gives validation errors since the id’s are used twice.

    Should wp_nav_menu behave this way? If so, is there a way to stop it?

    Thanks in advance

Viewing 1 replies (of 1 total)
  • I think this is a major issue with the new wp_nav_menu function, I had the same problem, the way I have resolved it temporarily is to edit the wp-includes/nav-menu-template.php
    Obviously this is only a temporary fix as editing the core files is never a good idea, as it will be overwritten everytime you upgrade. I’m hoping it will be fixed in the next version and that it will go back to class names instead of iD’s.

    On line 79 of nav-menu-template.php, replace:

    $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

    with:
    $output .= $indent . '<li' . $value . $class_names .'>';
    This will remove the ID from the li item.

    On line 314, after:

    foreach ( (array) $menu_items as $key => $menu_item ) {
    		$classes = (array) $menu_item->classes;
    		$classes[] = 'menu-item';
    		$classes[] = 'menu-item-type-' . $menu_item->type;

    add:

    $classes[] = 'menu-item-'. $menu_item->ID;
    This will add the page-id as a li class (eg: page-item-6), as it used to in previous version of wordpress.

    Hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘WP 3.0 wp_nav_menu creates unique ID for each nav item’ is closed to new replies.