Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to display my wordpress menu in the form of a simple tree like this:

  >First menu item

  >Second menu item

  >Third menu item

I know there is this wp_nav_menu() but how do I add class to sub-menu so that I can give some left margin and make it look like, it's nested?

share|improve this question

migrated from stackoverflow.com May 24 '13 at 13:57

This question came from our site for professional and enthusiast programmers.

It is likely that Wordpress does not support that out of the box for you (if you don't want to set each items class manually in the menu editor). One way to add the functionality you're looking for is to provide your own walker, see the docs about $walker on the codex page you've linked. –  hakre May 24 '13 at 9:52

1 Answer 1

Just add below css in your style,

ul ul {
  margin-left: 1.5em;


enter image description here

share|improve this answer
No, that's not what i mean, codex.wordpress.org/Function_Reference/wp_nav_menu this function returns all menu items as a single list(no nested ul li 's even if my menu has nested items) –  Rao May 24 '13 at 9:14
Can you demonstrate by what you mean by single list ? –  Rikesh May 24 '13 at 9:16
It returns something like this, <ul><li>First menu item</li><li>sub-menu-1</li><li>sub-sub-menu-1</li>...</ul> instead of <ul><li>First menu item</li><ul><li>sub-menu-1</li></ul><ul><li>sub-sub-menu-1</li></ul>...</ul> –  Rao May 24 '13 at 9:19
@Rao - It should not , How exactly you using wp_nav_menu function can you post that too ? –  Rikesh May 24 '13 at 9:22
yes it doesn't, my bad, there was no sub-menu in my custom menu, so it was displaying one ul and all li 's. –  Rao May 24 '13 at 9:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.