WordPress – wp nav menu filter to get rid of ul and li

I am trying to get rid of ul and li tags that wp_nav_menu function creates.
I am trying to get general result that would help in most of the cases.

Ok. Here is my code.

Read More
<?php

 $menuParameters = array(
 'container'       => false,
 'echo'            => false,
 'items_wrap'      => '%3$s',
 'depth'           => 0,
 );

 echo strip_tags(wp_nav_menu( $menuParameters ), '<a>' );

?>

So, where I need navigation, I’ll put this code and it will give me result only in the form of anchors.
For example:
Rather than giving

 <ul>
  <li><a href="#">item 1</a></li>
  <li><a href="#">item 2</a></li>
  <li><a href="#">item 3</a></li>
 </ul>

It would only return

  <a href="#">item 1</a>
  <a href="#">item 2</a>
  <a href="#">item 3</a>

This gives me much more power to customize the menu by just using html rather than writing jQuery or other hacks.

This works great if I don’t add any child menu / dropdown menu items. As this will also strip down the child menus. So, there won’t be any distinction if the anchor was of a child menu item or not.
I am having problem to modify it accordingly so it must show some difference in the “achors” having child anchors.
Any help?

Related posts

Leave a Reply