Need to specify a menu (2 posts)

  1. madmedic10
    Posted 3 years ago #

    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) {
            $searchform = ob_get_contents();
            $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

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

  2. bcworkz
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.