How do I avoid ID conflicts if I use the same menu TWICE on one page.
FIRST
wp_nav_menu( array( 'sort_column' => 'menu_order',
'theme_location'=>'menu', 'menu_class'=>'menu', 'menu_id'=>'menu' ) );
SECOND:
wp_nav_menu( array( 'sort_column' => 'menu_order',
'theme_location'=>'menu', 'menu_class'=>'menu2', 'menu_id'=>'menu2' ) );
ID conflicts are like "Duplicate ID menu-item-2456"... Any solutions?
How do I avoid ID conflicts if I use the same menu TWICE on one page.
FIRST
wp_nav_menu( array( 'sort_column' => 'menu_order',
'theme_location'=>'menu', 'menu_class'=>'menu', 'menu_id'=>'menu' ) );
SECOND:
wp_nav_menu( array( 'sort_column' => 'menu_order',
'theme_location'=>'menu', 'menu_class'=>'menu2', 'menu_id'=>'menu2' ) );
ID conflicts are like "Duplicate ID menu-item-2456"... Any solutions?
Share Improve this question asked Jun 15, 2012 at 18:08 AtadjAtadj 2,1828 gold badges29 silver badges40 bronze badges 2 |1 Answer
Reset to default 2The solution is not to call the same 'theme_location'
more than once. Theme location is intended to represent an explicit location within the template.
Just register a separate 'theme_location'
for each separate location within the template that you want to display a nav menu.
Consider your chosen 'theme_location'
names to be semantic names, representing the template location of the menu. You could use 'primary'
and 'secondary'
, or 'header'
and 'footer'
, etc.:
<?php
function wpse55380_setup_theme() {
// Register nav menu locations
register_nav_menus( array(
'header' => 'Header Menu',
'footer' => 'Footer Menu'
) );
}
add_action( 'after_setup_theme', 'wpse55380_setup_theme' );
...or:
<?php
function wpse55380_setup_theme() {
// Register nav menu locations
register_nav_menus( array(
'primary' => 'Primary Header Menu',
'secondary' => 'Secondary Header Menu'
) );
}
add_action( 'after_setup_theme', 'wpse55380_setup_theme' );
Then, it is up to the end user to assign custom menus to each Theme Location.
'theme_location'
s. I’ll remove my answer. – fuxia ♦ Commented Jun 15, 2012 at 18:54