Fay Kay
Fay Kay

Reputation: 45

Add class to wp_nav_menu

I'm trying to insert the below class into a wp_nav_menu. The class goes inside the <li> elements.

\<div class="menu-overlay__item-wrapper split-text" data-split-text-type="lines"\>.

I can get the first part to apply (menu-overlay__item-wrapper) but not the second part with the split text animation (data-split-text-type="lines").

The Custom Walker

class WP_Walker extends Walker_Nav_Menu
{
    function start_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<div class='menu-overlay__item-wrapper split-text js-split-text data-split-text-type= lines><ul class='sub-menu'>\n";
    }
    function end_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent</ul></div>\n";
    }
}

And the wp_nav_menu

      \<?php
      wp_nav_menu( array(
      'menu'              =\> 'primary', // match name to yours
      'theme_location'    =\> 'primary',
      'menu_class'        =\> 'menu-overlay js-menu-overlay',
      'fallback_cb'       =\> false,
      'container'         =\> false,
      'items_wrap'        =\> '%3$s',
      'walker' =\> new WP_Walker
      ));
      ?\>     

Upvotes: 0

Views: 47

Answers (0)

Related Questions