Add classes to wp_nav_menu list-items and anchors
-
As the topic title says, I’d like to add specific classes to the
<li>
and<a>
tags with my navigation. I know I can style the elements using.menu-name li a {}
in my CSS but I’m really trying to match my WordPress markup as closely as I can to my static HTML templates and match my BEM naming convention. As this is my first venture into creating a custom theme I’m hoping this will teach me (the hard way) a bit more about how it works, rather than taking the easy way out. That said, I am a novice.My current
wp_nav_menu
function looks like this:function html5blank_nav() { wp_nav_menu( array( 'theme_location' => 'header-menu', 'menu' => '', 'container' => false, 'container_class' => 'menu-{menu slug}-container', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul class="site-nav__list">%3$s</ul>', 'depth' => 0, 'walker' => '' ) ); }
And for reference, my static nav markup looks like this:
<nav class="site-nav"> <a href="#" class="page-head__logo"> <img src="img/interface/logo.png" srcset="img/interface/[email protected] 2x" alt="Wireforce logo" /> </a> <a href="#" id="site-nav__toggle">Menu</a> <ul class="site-nav__list"> <li class="site-nav__item"><a href="#" class="site-nav__link">Services</a></li> <li class="site-nav__item selected"><a href="#" class="site-nav__link">Security</a></li> <li class="site-nav__item"><a href="#" class="site-nav__link">Blog</a></li> <li class="site-nav__item"><a href="#" class="site-nav__link">About</a></li> <li class="site-nav__item"><a href="#" class="site-nav__link">Contact</a></li> </ul> </nav>
I know this may be a bit advanced for me at this stage but I suppose I’m only going to learn one way and the sooner I get into it the better. So I’d really appreciate some help/being pointed in the right direction on this as I imagine it’s something I’ll use again and again.
Thanks in advance!
- The topic ‘Add classes to wp_nav_menu list-items and anchors’ is closed to new replies.