• Ive added a search bar to my navigation menu by placing this in my functions.php:

    add_filter('wp_nav_menu_items','add_search_box', 10, 2);
    function add_search_box($items, $args) {
    
            ob_start();
            get_search_form();
            $searchform = ob_get_contents();
            ob_end_clean();
    
            $items .= '
    
    <li>' . $searchform . '</li>
    ';
    
        return $items;
    }

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

    The problem is that i have two menus on my site, and the search box shows up on both menus. Is there a way to specify which menu? Ive searched google and most of this forum with no luck. Thanks.

    My site is
    GearMoose

    i’ve deleted the code for now until i can find a solution.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code needs a way to differentiate which page it’s on somehow. Then you can wrap the search box code in an IF block that checks for this feature. Perhaps something passed in the arguments for the wp_nav_menu() call? Or one of the Conditional Tags?

Viewing 1 replies (of 1 total)
  • The topic ‘Need to specify a menu’ is closed to new replies.