0

I have div structure

<div class = 'main-menu'>
 <ul class = 'menu'>
  <li class = 'item1'></li>
  <li class = 'item2'></li>
 </ul>
</div>

But I want add div to menu

<div class = 'main-menu'>
 <ul class = 'menu'>
  <li class = 'item1'></li>
  <li class = 'item2'>
   <div class="adv_categories" id="adv_categories">
     <?php cp_create_categories_list( 'menu' ) ?>
   </div>
  </li>
 </ul>
</div>

How can I do that?

0

When using wp_nav_menu you can pass arguments to it which help you style the output, look at:

  • $container Whether to wrap the ul, and what to wrap it with. Allowed tags are div and nav. Use false for no container e.g. container => false .

  • $container_class the class that is applied to the container.

  • $container_id The ID that is applied to the container.

  • $menu_class CSS class to use for the containing div element which forms the default menu, or the ul element when a custom menu is configured in the admin interface.

  • $before Output text before the of the link.

  • $after Output text after the of the link.

  • $link_before Output text before the link text.

  • $link_after Output text after the link text.

  • $items_wrap Whatever to wrap the items with an ul, and how to wrap them with.

So in you case you can use

array( 'link_before' => '<div class="your_class">' , 'link_after' => '</div>');

But if you ask me you can probably do what you want with the classes WordPress prints out anyway.

http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items

  • It is not that I want. Your solution just wraps link to div. – Alexander Kolovsky Aug 31 '15 at 15:32
0

For this type of result, you need to get your hands dirty and use a custom nav menu walker that will give you full control of the output the menu produces. There are many intricacies involved regarding how you plan to handle multiple levels in the menu (are you going for top level only?).

From what I see, you don't want to just wrap menu items, but also want to insert multiple menu items.

You could also give the 'walker_nav_menu_start_el' filter a go as it gives you access to the link output and you could add markup before the output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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