0

In my theme the top menu is like this:

<nav>
  <ul>
       <li>
            <a class='active' data-scroll-nav='0'>Home</a>
       </li>
       <li>
            <a data-scroll-nav='1'>Services</a>
       </li>
  </ul>
</nav>

By using a custom walker function, I've been able to clean the ul and li tags of unwanted classes and IDs. Now I need to to add "data-scroll-nav". How do I write a custom function to add this to the menu anchors? The menu code shown above will work like this.

1 Answer 1

1

Thank god.. i've solved it my own. this is the function i used to update the anchor tags.

function my_walker_nav($item_output, $item, $depth, $args) {
    $menu_locations = get_nav_menu_locations();

if(!empty( $item->description ))
    $description = $item->description;
else {
   $description = ''; 
}

 if ($item->menu_order == 1){

 $item_output = preg_replace('/<a /', '<a data-scroll-nav="'.$description.'" ', $item_output, 1);

}
    return $item_output;
}
add_filter('walker_nav_menu_start_el', 'my_walker_nav', 10, 4);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.