Support » Plugin: Search box on Navigation Menu » Search box for specific Navigation Menu

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello
    I found a similar code, but I can not solve the problem. This is the code:

    add_filter('wp_nav_menu_items', 'add_search_form', 10, 2);
    function add_search_form($items, $args) {
    if( $args->theme_location == 'MENU-NAME' )
            $items .= '<li class="search"><form role="search" method="get" id="searchform" action="'.home_url( '/' ).'"><input type="text" value="search" name="s" id="s" /><input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" /></form></li>';
            return $items;

    If you find the solution, please contact me. Thank you!

    bass03 you have 2 mistakes:

    1. Menu-name should be menu location
    2. You need an “else { return $items;}” to return other menus without search.


    I am trying to figure this out as well.

    Mike, I’m not sure what you mean?

    How should the code look if I only want the search box to show up in my menu named “top menu”? what would ‘menu location’ be?

    I’m not a coder so where would the “else { return $items;}” code go?


    Here is what I scraped together which works:
    add_filter(‘wp_nav_menu_items’,’add_search_box’, 10, 2);
    function add_search_box($items, $args) {
    if( $args->theme_location == ‘primary’ )
    $searchform = ob_get_contents();
    $items .= $searchform ;
    return $items;
    return $items;

    Thank you. Worked like a charm!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search box for specific Navigation Menu’ is closed to new replies.