Sage + soil: extend navWalker

Hi,
i would modify NavWalker made by soil plugin to obtain

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

instead of

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

Can you help me?
TY

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.