0
votes

Im using a bootstrap nav walker for a wordpress site and trying as im trying to re-create a premium theme (only temporary) so matching their markup to save time.

I need to add a attribute to the <ul> so that its <ul data-plugin="menu">... but i cant see anything which can help me how to do so. I can see how to add attributes to menu links but not the menu itself (without adding it via jQuery etc).

My output for the menu is pretty simple:

<?php
wp_nav_menu( array(
    'menu'       => 'top',
    'depth'      => 2,
    'container'  => false,
    'menu_class' => 'site-menu scrollable-content',
    'walker'     => new wp_bootstrap_navwalker())
);
?>
1
Yes, but cant see anything about adding custom attributes... - WillL
given you are specifying container => false I'm assuming you need custom attributes on the <ul> items container, right? - DRC
Correct... Sorry iv just realised it stripped out the html i had in my question. So it needs to be: <ul data-plugin="menu"> . Will update the question with that too. - WillL

1 Answers

1
votes

to add custom attributes on the items container you could specify a custom template in items_wrap

'items_wrap' => '<ul data-plugin="menu" id="%1$s" class="%2$s">%3$s</ul>'

resulting in this call to wp_nav_menu

<?php
wp_nav_menu( array(
    'menu'       => 'top',
    'depth'      => 2,
    'container'  => false,
    'menu_class' => 'site-menu scrollable-content',
    'walker'     => new wp_bootstrap_navwalker(),
    'items_wrap' => '<ul data-plugin="menu" id="%1$s" class="%2$s">%3$s</ul>'
);
?>

items_wrap is used like this to build the final nav menu:

$nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );