craigpearson/bem-walker-nav-menu

BEM naming for WordPress navigation menus.

3.1.1 2020-12-03 17:25 UTC

This package is auto-updated.

Last update: 2024-11-16 20:01:36 UTC


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';
}

License

WTFPL