Wordpress: add custom ID to ul in wp_nav_menu
Solution 1
wp_nav_menu
accepts the key menu_id
in its options array. Set it to the ID you want, e.g:
wp_nav_menu(array(
'menu_id' => 'menu'
));
Solution 2
You can explicitly set the id in the html by defining items_wrap
, and make sure walker
is not set to some custom function:
wp_nav_menu( array(
'theme_location' => 'main-menu'
'items_wrap' => '<ul id="menu" class="%2$s">%3$s</ul>',
'walker' => '',
));
This is incomplete info; 1st attempt to use:
'fallback_cb' => false,
If you menu doesn't appear, that means you have not created any menu and that means its taking the fallback function take care for that.
So go and create a menu first. :D
Solution 3
Giving the ul an id that's the same as the class of its container is asking for trouble, but this should work:
<?php
function showMenu(){
$args = array(
'menu_id' => 'menu'
);
wp_nav_menu($args);
}
showMenu();
?>
The WordPress Codex has a page detailing all options for the wp_nav_menu() function: http://codex.wordpress.org/Function_Reference/wp_nav_menu
Comments
-
Déjà Bond almost 2 years
I am trying to alter the wp_nav_menu to output the html like the below example.
<div class="menu"> <ul id="menu">
The original output
<div class="menu"> <ul>
I cant do it with jQuery or javascript, Its have to be php code
-
Déjà Bond over 11 yearsthe output is same the original, like i'm never edit the code!!
-
Déjà Bond over 11 yearsthe output is same the original, like i'm never edit the code!!
-
Chris Herbert over 11 yearsShow us the output, please.
-
freejosh over 11 years@JimmyTodd Can you post the PHP code you're using to output the menu?
-
Déjà Bond over 11 yearsthis is the code img560.imageshack.us/img560/9905/wpmenug.png and this is the output jsfiddle.net/v9rvA
-
freejosh over 11 yearsWhat theme are you using? Maybe it disregards the option
-
Chris Herbert over 11 yearsAre you sure you're editing the right file? Are you changing the code on your local server but refreshing the remote server? It really should add that id.
-
freejosh over 11 yearsAre you using any other plugins that might affect the output of the menu?
-
Déjà Bond over 11 yearsno the all work i do in localhost and i'm really sure every thing is alright, and this why it driving me crazy :(
-
Chris Herbert over 11 yearsAs a test, remove wp_nav_menu() from your code completely. If the menu is still there then something else is going on.
-
Déjà Bond over 11 yearsdone it before and done it now too to be sure, when i remove the wp_nav_menu() the whole nave disappear