目前我的搜索栏显示在菜单的末尾(在最后一个li)如何更改自定义wordpress菜单中的搜索栏排序?

问题描述:

I am using this code in my top menu (function.php). But through this code the search bar will display at the end of the menu (i.e. the last li).

How can I change the ordering? I have to place it in the first li. Is it possible or not?

/**
  * Add search box to primary menu
  */
function wpgood_nav_search($items, $args) {
  // If this isn't the primary menu, do nothing
  if( !($args->theme_location == 'topmenu') ) 
    return $items;
  // Otherwise, add search form
    return $items . '<li class="search-in-menu"><p id="hm-search1"><i class="fa fa-search"></i></p>' . get_search_form(false) . '</li>';
}
add_filter('wp_nav_menu_items', 'wpgood_nav_search', 10, 2);

我在顶级菜单中使用此代码( function.php code>)。 但是通过这段代码,搜索栏将显示在菜单的末尾(即最后的 li code>)。 p>

如何更改排序? 我必须将它放在第一个 li code>中。 是否有可能? p>

  / ** 
 *将搜索框添加到主菜单
 * / 
function wpgood_nav_search($ items,$ args){
 /  /如果这不是主菜单,则不执行任何操作
如果(!($ args-&gt; theme_location =='topmenu'))
返回$ items; 
 //否则,添加搜索表单
返回$ 物品。  '&lt; li class =“search-in-menu”&gt;&lt; p id =“hm-search1”&gt;&lt; i class =“fa fa-search”&gt;&lt; / i&gt;&lt; / p&gt;  “  。  get_search_form(false)。  '&lt; / li&gt;'; 
} 
add_filter('wp_nav_menu_items','wpgood_nav_search',10,2); 
  code>  pre> 
  div>

push it at front and return the value

/**
 * Add search box to primary menu
 */
function wpgood_nav_search($items, $args) {
    // If this isn't the primary menu, do nothing
    if( !($args->theme_location == 'topmenu') ) 
    return $items;
    // Otherwise, add search form
    return '<li class="search-in-menu"><p id="hm-search1"><i class="fa fa-search"></i></p>' . get_search_form(false) . '</li>'.$items;
}
add_filter('wp_nav_menu_items', 'wpgood_nav_search', 10, 2);