• thetoolman123

    (@thetoolman123)


    Hi there,

    I would like to add a tooltip to one of my menu items using Bootstrap. I can add a class to the menu item, but how do I add data attributes?

    Any help would be appreciated.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @thetoolman123

    To add a custom attribute like to a specific nav menu item’s anchor, Their is a filter available to add this nav_menu_link_attributes

    add_filter( 'nav_menu_link_attributes', 'filter_function_name', 10, 3 );
    function filter_function_name( $atts, $item, $args )
    {
      // Set the menu ID(You can get ID from the chrome inspector for the specific menu item)
      $menu_link = 1215;
      // Conditionally match the ID and add the attribute and value
      if ($item->ID == $menu_link) {
        $atts['data-toggle'] = 'tooltip';
      }
      //Return the new attribute
      return $atts;
    }

    for info https://codex.www.ads-software.com/Plugin_API/Filter_Reference/nav_menu_link_attributes

    Thank You

    Hello there,

    I want to add attribute to multiple nav menu item’s anchor. how to achieve this above filter.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding a Bootstrap tooltip to a menu item?’ is closed to new replies.