WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#13597 closed defect (bug) (fixed)

Using the same menu in multiple theme_location resulting in duplicate ids

Reported by: sushicodeur Owned by: filosofo
Milestone: 3.0 Priority: normal
Severity: minor Version: 3.0
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

I've a site using multiple menus. The menu are registered this way

if ( function_exists('register_nav_menus') ) {
  register_nav_menus(
    array(
      'social-top' => 'Top social menu',
      'social-bottom' => 'Bottom social menu',
    )
  );
}

I wish to use the same menu (named social) for the two theme locations. I call the menu with these args :

<?php
  $menu_args = array(
    'container'       => '',
    'theme_location'  => 'social-top', // and social-bottom the next time
  );
  wp_nav_menu($menu_args); 
?>

Resulting in the same opening tag for the two menus (since the id is constructed using the menu slug), which is not W3C valid :

<ul id="menu-social"><!-- found twice in the same page -->

The "container_id" option described here http://codex.wordpress.org/Function_Reference/wp_nav_menu seems to have no effect.

Attachments (1)

unique-menu-container-ids.13597.diff (2.4 KB) - added by filosofo 4 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 filosofo4 years ago

  • Owner set to filosofo
  • Status changed from new to accepted

comment:2 filosofo4 years ago

  • Keywords has-patch added

comment:3 eveevans4 years ago

  • Severity changed from normal to minor

I think you can use wp_get_nav_menu_items() and wp_get_nav_menus() for have more control in the custom menus

comment:4 ryan4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [15034]) Unique menu container ids. Props filosofo. fixes #13597

Note: See TracTickets for help on using tickets.