• Resolved Bloke

    (@bloke)


    I am trying to add a search box to my navigation bar. It works but I have a mega menu. So anything below it will have search boxes also. Is there a way to only display it in the main nav bar?

    add_filter('wp_nav_menu_items','add_search_box', 10, 2);
    function add_search_box($items, $args) {
    if ($args->theme_location == 'First Menu' || 'Second Menu') {
    ob_start();
    get_search_form();
    $searchform = ob_get_contents();
    ob_end_clean();
    
    $items .= '<li class="mega-menu-item mega-menu-item-type-custom mega-menu-item-object-custom mega-menu-item-1173">' . $searchform . '</li>';
    
    }
    return $items;
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Adding search to navigation bar’ is closed to new replies.