craigpearson / bem-walker-nav-menu
BEM naming for WordPress navigation menus.
Installs: 2 152
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 4
Open Issues: 1
Type:package
Requires
- php: >=5.6
README
BEM naming for WordPress navigation menus.
Installation
You can manually download it and install it in your plugins folder or install it via Composer:
composer require craigpearson/bem-walker-nav-menu
Usage
<nav class="nav"> <?php wp_nav_menu([ 'walker' => new CP\BEM\navWalker, ]); // Will generate: // <ul id="..." class="nav__list"> // <li class="nav__item ... nav__item--123"> // <a href="..." class="nav__link">...</a> // <ul class="sub-nav"> // <li class="sub-nav__item"> // ... ?> </nav>
Extend the class to change the HTML classes.
<?php class CustomWalkerNavMenu extends \CP\BEM\navWalker { protected $prefix = 'c'; protected $navListClass = 'menu__list'; protected $navItemClass = 'menu__item'; protected $navLinkClass = 'menu__link'; protected $subNavClass = 'sub-menu'; protected $subNavItemClass = 'sub-menu__item'; protected $subNavLinkClass = 'sub-menu__link'; }