Title: Customized wp_nav_menu()
Last modified: August 20, 2016

---

# Customized wp_nav_menu()

 *  [wp_oulu](https://wordpress.org/support/users/wp_oulu/)
 * (@wp_oulu)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/)
 *     ```
       <div class="example">
       <h1>Menu</h1>
       <ul>
           <li>sub-menu</li>
           <li>sub-menu</li>
           <li>sub-menu</li>
       </ul>
       </div><!-- end of example -->
   
       <div class="example>
       <h1>Menu</h1>
       <ul>
           <li>sub-menu</li>
           <li>sub-menu</li>
           <li>sub-menu</li>
       </ul>
       </div><!-- end of example -->
       ```
   
 * I’m trying to make a menu with wp_nav_menu() and I want to achieve a clean code
   like this. I’m trying to do it with a custom walker but I don’t have experience
   with this. I think I have to overwrite a class but …
 * My idea is using h1 tags to menu items and and unordered list to submenu items.
 * Coud you help me with the code?? Thanks for all

Viewing 15 replies - 1 through 15 (of 34 total)

1 [2](https://wordpress.org/support/topic/customized-wp_nav_menu/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/customized-wp_nav_menu/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/customized-wp_nav_menu/page/2/?output_format=md)

 *  [ahuggins](https://wordpress.org/support/users/ahuggins/)
 * (@ahuggins)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2237969)
 * I’m sure you have a reason, but I am not seeing it as to why to NOT use the default
   html output when using wp_nav_menu()?
 * Which I think is like:
 *     ```
       <ul>
         <li>Top Level Menu Item</li>
            <ul>
               <li>Sub Menu Item</li>
               <li>Another submenu Item</li>
            </ul>
         <li>Another Top Level Menu Item</li>
        </ul>
       ```
   
 * Unless you are trying to do something for SEO, which I am not sure is the best
   idea, the default output is great and very usable with CSS. Also it is easier
   and would be more portable.
 * If there is a specific styling issue (which there could be), [this article](http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output)
   may help.
 * Hope that helps
 *  [Mitchell Bundy](https://wordpress.org/support/users/mitchbundy/)
 * (@mitchbundy)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2237977)
 * You should NEVER EVER use h1 tags for anything other than the page title, and
   it should only be used once per page. I’d recommend using the default output 
   and styling it.
 *  [Steffen Jørgensen](https://wordpress.org/support/users/jint/)
 * (@jint)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2237983)
 * > You should NEVER EVER use h1 tags for anything other than the page title, and
   > it should only be used once per page…
 * Unless you’re using HTML5 markup, there you can have as many H1-tags as you like:
 *     ```
       <section class="articles">
         <article>
           <h1>Title #1</h1>
         </article>
         <article>
           <h1>Title #2</h1>
         </article>
       </section>
       ```
   
 * However, I would also recommend using the default HTML-output that the wp_nav_menu();
   gives you
 *  [jeFFF](https://wordpress.org/support/users/jefff/)
 * (@jefff)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2237985)
 * Hello,
 * Can you just explain why is it so bad to override wp_nav_menu HTML output ?
    
   The core WordPress coding team offers you that opportunity, I don’t see the pont
   of avoiding it, HTML markups do not hurt 😉
 * For example, how can you add a custom “sub-menu” CSS class to a second level 
   menu ?
 *     ```
       <ul class="menu">
           <li>
             <ul class="sub-menu">
               <li></li>
             </ul>
           </li>
         </ul>
       ```
   
 * How can you add a custom CSS class to an LI item to tell it that it has a child
   menu :
 *     ```
       <li class="has-child">
           <ul>
             <li></li>
           </ul>
         </li>
       ```
   
 * (well, for this one, you can do it with a hook).
 * My point is, if you know what you are doing, you can do anything with core libraries
   overrides ( and I don’t say hack 😉 )
 * Cheers
    jeFFF
 *  [TimDesain](https://wordpress.org/support/users/timdesain/)
 * (@timdesain)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238010)
 * in function.php
 *     ```
       add_action( 'after_setup_theme', 'td_setup' );
       function td_setup() {
       	register_nav_menus( array(
       		'menu_top' => 'Menu TOP' ,
       		'menu_bot' => 'Menu BOT'
       	) );
       }
       ```
   
 * in theme’s file
 *     ```
       <div class="menu-title">Title TOP</div>
       <?php wp_nav_menu( array( 'container_class' => 'menu01', 'theme_location' => 'menu_top' ) ); ?>
       <div class="menu-title">Title BOT</div>
       <?php wp_nav_menu( array( 'container_class' => 'menu02', 'theme_location' => 'menu_bot' ) ); ?>
       ```
   
 * set your menus
    `http://DOMAIN/wp-admin/nav-menus.php`
 *  [davidcancool](https://wordpress.org/support/users/davidcancool/)
 * (@davidcancool)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238014)
 * Just wanted to say I enjoyed the post.I have to speakyour web site is very cool
   I really like your theme! I’ll bookmark it and come back later.
    _[link removed]_
 *  [Marventus](https://wordpress.org/support/users/marventus/)
 * (@marventus)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238024)
 * Hello everybody,
 * It seems like the Original Poster went MIA after his/her question.
    IMHO, the
   answer to the OP’s problem seems to rely on a custom nav walker, since the changes
   to the default walker that are necessary in order to generate his/her desired
   output are very minimal and pretty straightforward. [@wp_oulu](https://wordpress.org/support/users/wp_oulu/):
   if you get back to me on this, I’ll tell you how to do it.
 *  Thread Starter [wp_oulu](https://wordpress.org/support/users/wp_oulu/)
 * (@wp_oulu)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238025)
 * I simply didn’t write because nobody answer what I have asked. If you have the
   solution, please post it.
 * Thank you and best regards.
 *  [Marventus](https://wordpress.org/support/users/marventus/)
 * (@marventus)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238026)
 * That makes sense, 😉
 * This [custom nav walker](http://pastebin.com/wSzKBLXe) should do the trick. Please
   note that I have only included the `start_el` function in the custom walker because
   it is the only function that needed changing, but if you wish to do further modifications,
   you might have to include other functions from the default walker as well. You
   can see the complete default walker code inside `[wp_root]/wp-includes/nav-menu-
   template.php`.
 * **Edit:** I almost forgot to mention that if you don’t want any container divs
   wrapping your menu, pass a `false` value to the wp_nav_menu’s `container` argument.
 * **Edit 2: **The custom nav walker will output smth like this:
 *     ```
       <ul>
          <h1 id="nav-item-1">
             <a href="link-1">
             </a>
          </h1>
          <h1 id="nav-item-2">
             <a href="link-2">
             </a>
             <ul class="sub-menu">
                <li id="sub-item-1">
                   <a href="sub-link-1">
                   </a>
                <li id="sub-item-2">
                   <a href="sub-link-2">
                   </a>
             </ul>
          </h1>
       </ul>
       ```
   
 * This is not valid HTML, because you can’t place a heading tag, which is a block
   tag, inside a ul tag, another block tag. If you want your code to be valid, you
   will have to use the undocumented `items_wrap` argument and pass the following
   value to it: `%3$s` when calling `wp_nav_menu`. That will get rid of the wrapping
   `
   <ul>` tag.
 *  [Oleg Dudkin](https://wordpress.org/support/users/olegdudkin/)
 * (@olegdudkin)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238028)
 * Hi,
    A small edit to previous poster. To avoid including submenu inside h1 tag,
   change:
 * `$output .= $indent . '<h1' . $id . $value . $class_names .'>';`
    to `$output.
   = $indent . '<div' . $id . $value . $class_names .'>';`
 * ;
 *     ```
       $item_output .= '<a'. $attributes .'>';
       $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
       $item_output .= '</a>';
       ```
   
 * to
 *     ```
       $item_output .= '<h1><a'. $attributes .'>';
       $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
       $item_output .= '</a></h1>';
       ```
   
 * and
 *     ```
       function end_el(&$output, $item, $depth) {
       	$output .= "</h1>\n";
       }
       ```
   
 * to
 *     ```
       function end_el(&$output, $item, $depth) {
       	$output .= "</div>\n";
       }
       ```
   
 * p.s. Why have you chosen so difficult way to get penalty in google?
 *  [Speed_FANat1c](https://wordpress.org/support/users/speed_fanat1c/)
 * (@speed_fanat1c)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238029)
 * I want to ask a question, not creating another thread: I use
 * `<?php wp_nav_menu( array( 'container' => false ) ); ?>`
 * why could be this pringing me with a div?
 * `<div class="menu"><ul><li class="current_page_item"><a href="http://localhost/
   wordpress/" title="Home">Home</a></li><li class="page_item page-item-4"><a href
   ="http://localhost/wordpress/resume/" title="Resume">Resume</a></li><li class
   ="page_item page-item-2"><a href="http://localhost/wordpress/sample-page/" title
   ="Sample Page">Sample Page</a></li></ul></div>`
 * ?
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238030)
 *     ```
       <?php wp_nav_menu( array( 'container' => ' ' ) ); ?>
       ```
   
 * works better than false for me
 *  [Speed_FANat1c](https://wordpress.org/support/users/speed_fanat1c/)
 * (@speed_fanat1c)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238031)
 * > works better than false for me
 * Does not for me 🙁 it still puts in div container.
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238032)
 * Odd… here’s mny output
 *     ```
       <nav id="access" role="navigation">
       	<h3 class="assistive-text">Main menu</h3>
       	<div class="skip-link"><a class="assistive-text" href="#content" title="Skip to primary content">Skip to primary content</a></div>
       	<div class="skip-link"><a class="assistive-text" href="#secondary" title="Skip to secondary content">Skip to secondary content</a></div>
   
       	<ul id="nav" class="menu"><li id="menu-item-688" cla
       ```
   
 * You can see there is no div in there…..
 *     ```
       <nav id="access" role="navigation">
       	<h3 class="assistive-text"><?php _e( 'Main menu', 'rvoodoo' ); ?></h3>
       	<div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content', 'rvoodoo' ); ?>"><?php _e( 'Skip to primary content', 'rvoodoo' ); ?></a></div>
       	<div class="skip-link"><a class="assistive-text" href="#secondary" title="<?php esc_attr_e( 'Skip to secondary content', 'rvoodoo' ); ?>"><?php _e( 'Skip to secondary content', 'rvoodoo' ); ?></a></div>
   
       	<?php wp_nav_menu( array( 'theme_location' => 'primary', 'container' => '', 'menu_id' => 'nav' ) ); ?>
       ```
   
 * Is how I call it
 *  [Speed_FANat1c](https://wordpress.org/support/users/speed_fanat1c/)
 * (@speed_fanat1c)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/#post-2238034)
 * thanks for the answer, but I already changed the css styling according to the
   html which is printed by wordpress.

Viewing 15 replies - 1 through 15 (of 34 total)

1 [2](https://wordpress.org/support/topic/customized-wp_nav_menu/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/customized-wp_nav_menu/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/customized-wp_nav_menu/page/2/?output_format=md)

The topic ‘Customized wp_nav_menu()’ is closed to new replies.

## Tags

 * [wp_nav_menu()](https://wordpress.org/support/topic-tag/wp_nav_menu/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 34 replies
 * 19 participants
 * Last reply from: [Arie Putranto](https://wordpress.org/support/users/arieputranto/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/customized-wp_nav_menu/page/3/#post-2238101)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
