Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Walker_Nav_Menu & Top_Bar_Walker class #555

Closed
lepressing opened this issue Nov 19, 2015 · 1 comment
Closed

Walker_Nav_Menu & Top_Bar_Walker class #555

lepressing opened this issue Nov 19, 2015 · 1 comment

Comments

@lepressing
Copy link

Is it possible to remove the link from the HREF and replace it by an "#" ?
something like:
$attributes .= ! empty( $item->url ) ? ' href=" # "' : '';

Thanks for your help !

@lepressing
Copy link
Author

I found a way, I don't know if it's the best.
I created a function :

add_filter( 'nav_menu_link_attributes', 'my_nav_menu_attribs', 10, 3 );
function my_nav_menu_attribs( $atts, $item, $args )
{
  $menu_target = $item->url;  // The ID of the target menu ou URL comme là.

  if ($item->url == $menu_target) {   // inspect $item
      $atts['data-scroll-nav'] = $menu_target;
      $atts['href'] = '#';
      //$attributes .= ! empty( $item->url )        ? ' href=" # "' : '';

  }
  return $atts;
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant