Roots Discourse

Sage + soil: extend navWalker

i would modify NavWalker made by soil plugin to obtain

<li class="menu-home">
  <a href="/" data="Home">Home</a>
<li class="menu-sample-page">
   <a href="/sample-page/" data="Sample Page">Sample Page</a>

instead of

<li class="menu-home">
  <a href="/">Home</a>
<li class="menu-sample-page">
   <a href="/sample-page/">Sample Page</a>

Can you help me?

Have you tried sth like this?

add_filter( 'nav_menu_link_attributes', function ( $atts, $item, $args ){
    $title = apply_filters( 'the_title', $item->title, $item->ID );
    $atts['data-page'] = $title;
    return $atts;
}, 10, 3 );

Not tested though :sweat_smile:

works like a charm TY

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.