Title: Adding div to nav menu
Last modified: August 20, 2016

---

# Adding div to nav menu

 *  Resolved [StuFu2](https://wordpress.org/support/users/stufu2/)
 * (@stufu2)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/adding-div-to-nav-menu/)
 * Hi,
 * I am working with the standard wp_nav_menu and wanted to know if it is possible
   to insert a classed div into the HTML markup to surround the first sub menu. 
   So the markup would look like:
 *     ```
       <div class="menu-header">
           <ul class="menu">
               <li class="menu-item"><a href="#">Page</a>
                   <div class="subContainer">
                       <ul class="sub-menu">
                          <li>...</li>
                       </ul>
                   </div>
               </li>
           </ul>
       </div>
       ```
   
 * I would like to add the “subContainer” div in.
 * Do I need to edit this line, or is there a different solution?
 * `<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location'
   => 'primary' ) ); ?>`
 * Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [santosh.sahoo](https://wordpress.org/support/users/santoshsahoo/)
 * (@santoshsahoo)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/adding-div-to-nav-menu/#post-2154446)
 * you can use a filter to add different class to differen menu items.
 * Try this , it may help u.
 *     ```
       add_filter('nav_menu_css_class', 'auto_custom_type_class', 10, 2 );
       function auto_custom_type_class($classes, $item) {
   
           if ($item->type_label == "CUSTOM_TYPE_NAME"){
               $classes[] = "New_Class";
           }
   
           return $classes;
       }
       ```
   
 * just change CUSTOM_TYPE_NAME to the name of your custom post type and New_Class
   with the name of your class and paste this snippet in your theme’s functions.
   php file.
 * You can also use the filter named “wp_nav_menu”
 * check this out,
    [](http://wpfirstaid.com/tag/wp_nav_menu/)
 * Hope this helps
 *  Thread Starter [StuFu2](https://wordpress.org/support/users/stufu2/)
 * (@stufu2)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/adding-div-to-nav-menu/#post-2154542)
 * Thanks santosh!
 * I had a hard time deciphering that code and couldn’t get it to work. Mostly because
   I am unsure of what you mean by “the name of your custom post type”. Sorry, I’m
   still new to PHP and WordPress.
 * That link you provided was really intriguing though and I’ll be holding on to
   that for other modifications I may make to my navigation.
 * For this I decided to avoid the PHP route and use jQuery instead by inserting
   the div with the before and after methods:
 * [http://api.jquery.com/before/](http://api.jquery.com/before/)
    [http://api.jquery.com/after/](http://api.jquery.com/after/)
 * Thanks again for the response!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding div to nav menu’ is closed to new replies.

## Tags

 * [div](https://wordpress.org/support/topic-tag/div/)
 * [menu](https://wordpress.org/support/topic-tag/menu/)
 * [nav](https://wordpress.org/support/topic-tag/nav/)

 * 2 replies
 * 2 participants
 * Last reply from: [StuFu2](https://wordpress.org/support/users/stufu2/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/adding-div-to-nav-menu/#post-2154542)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
