最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Add button to menu item at the same row

programmeradmin1浏览0评论

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);
发布评论

评论列表(0)

  1. 暂无评论