I am changing wp_nav_menu() to make it a listless navigation menu (i.e., no unordered list or list item tags) Normally the menu <li> has the .current-menu-item class attached to it when active. But is there a way to give it to the anchor instead?

<a class="current-menu-item"></a>

Edit: This is currently what I'm doing to remove the tags... if there's a custom walker solution that would be ideal. I'd prefer not having to resort to using any javascript if possible.

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

echo strip_tags(wp_nav_menu( $menuParameters ), '<a>' );
  • Please elaborate on how exactly are you applying your tweaks. – Rarst Jan 31 '14 at 16:40
  • 2
    I think you'd need to look at a custom Walker for this. Check out the Nav Menu docs for starters, and you'll find the Walker_Nav_Menu class (whcih you extend to make your custom walker) in /wp-includes/nav-menu-template.php. If that is what you want, update the question and I'll be happy to help. – David Gard Jan 31 '14 at 16:41
  • The question is what do you want to achieve? Basically you can style your a elements like you want even if wrapped with li tags – Luckyfella Aug 4 '17 at 10:18

Your Answer

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

Browse other questions tagged or ask your own question.