admin管理员组

文章数量:1418627

I tried to add a button to a the menu items which have children with the following code:

  function add_button( $output, $item, $depth, $args ){
      if (in_array("menu-item-has-children", $item->classes)) {
          $output .='<button type="button" class="btn btn-circle"><i class="fa fa-chevron-circle-down"></i> </button>';
      }
      return $output;
  } 
  add_filter( 'walker_nav_menu_start_el', 'add_button',10,4);

The problem is that are in the next row after the item, but i want them to appear right beside the item. How can I do that?

I tried to add a button to a the menu items which have children with the following code:

  function add_button( $output, $item, $depth, $args ){
      if (in_array("menu-item-has-children", $item->classes)) {
          $output .='<button type="button" class="btn btn-circle"><i class="fa fa-chevron-circle-down"></i> </button>';
      }
      return $output;
  } 
  add_filter( 'walker_nav_menu_start_el', 'add_button',10,4);

The problem is that are in the next row after the item, but i want them to appear right beside the item. How can I do that?

Share Improve this question asked Jul 25, 2019 at 11:24 xxrayxxray 1
Add a comment  | 

1 Answer 1

Reset to default 0

Please try something like this.

    function add_button( $output, $item, $depth, $args ){
          if (in_array("menu-item-has-children", $item->classes)) {
              $output ='<button type="button" class="btn btn-circle">
<i class="fa fa-chevron-circle-down"></i> 
</button>'.$output;
          }
          return $output;
      } 
      add_filter( 'walker_nav_menu_start_el', 'add_button',10,4);

本文标签: Add button to menu item at the same row