dongzhi1949 2017-07-04 10:07 采纳率: 100%
浏览 349

如何将搜索栏添加到wordpress中的移动菜单?

I've added this code to my functions.php file:

function wpgood_nav_search( $items, $args ) {
$items .= '<li>' . get_search_form( false ) . '</li>';
return $items;
}
add_filter( 'wp_nav_menu_items','wpgood_nav_search', 10, 2 );

I've found it here: adding search bar to the nav menu in wordpress

The problem: this code adds the search bar to desktop and mobile menus, but I need to add the search bar only to my mobile menu, because the desktop version of my site already has a search widget in the left sidebar.

How can I do this? Please, help me. Thanks!

Initializiation of my menus in functions.php :

// Initialize navigation menus
register_nav_menus(
    array(
        'primary-menu' => esc_html__( 'Primary Menu', 'bento' ),
        'footer-menu' => esc_html__( 'Footer Menu', 'bento' ),
    )
);

Thank you so much for your help! Finally I have decided to use my initial code and edit the searchbar's position and style with css, because I am not so good in coding:)

  • 写回答

4条回答 默认 最新

  • dpswo40440 2017-07-04 10:22
    关注

    Use the javascript code for adding the search box for mobile menu

    $("ul.primary-mobile-menu').append('
    // your html code to append
    <li><form role="search" method="get" id="searchform" class="search-form" action="https://bookyspace.com/"><div class="search-form-wrap"> <input type="text" value="" name="s" id="s" class="search-form-input" placeholder="Знайти.."> <input type="submit" id="searchsubmit" class="button submit-button" value=""></div></form></li>
    ');
    

    Thanks

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大