Wordpress search field in specific menu bar

admin

Administrator
Staff member
I added a search field to my menu bars by using this code;

Code:
function menu_search($items){
    $search = '<li class="menusearch">';
    $search .= '<form method="get" id="searchform" action="/">';
    $search .= '<input type="text" class="field" name="s" id="s" placeholder="Search" />';
    $search .= '<input type="submit" class="menusubmit" name="submit" id="searchsubmit" value="Search" />';
    $search .= '</form>';
    $search .= '</li>';

    return $items . $search;
}
add_filter('wp_nav_menu_items','menu_search');

But this adds the bar to all my menus, since I'm using multiple menus this is a problem. How can I make it so that the search bar only shows up in my main navigation bar?

I tried using the tutorial found here;<a href="http://www.wpbeginner.com/wp-themes/how-to-add-custom-items-to-specific-wordpress-menus/" rel="nofollow">http://www.wpbeginner.com/wp-themes/how-to-add-custom-items-to-specific-wordpress-menus/</a> but the search bar won't show up in my menu bar at all anymore. Maybe I'm using the name or the theme location wrong, this is what shows up in my menu screen 'Default (The Main Menu)'.

This is the rest of my functions file if needed;

Code:
&lt;?php
ob_start();
if ( function_exists( 'add_image_size' ) ) { add_image_size( 'orbit-custom', 920, 300 ); }

/**
 * Add a search bar to the navigation menu.
 *
 * @since Twenty Twelve 1.0
 */

function menu_search($items){
    $search = '&lt;li class="menusearch"&gt;';
    $search .= '&lt;form method="get" id="searchform" action="/"&gt;';
    $search .= '&lt;input type="text" class="field" name="s" id="s" placeholder="Search" /&gt;';
    $search .= '&lt;input type="submit" class="menusubmit" name="submit" id="searchsubmit" value="Search" /&gt;';
    $search .= '&lt;/form&gt;';
    $search .= '&lt;/li&gt;';

    return $items . $search;
}
add_filter('wp_nav_menu_items','menu_search');

// This adds more than one menu location
add_action( 'init', 'register_multiple_menus' );
function register_multiple_menus() {
    register_nav_menus(
        array(
            'footer-nav-mid' =&gt;  'Middle Footer Navigation',
            'footer-nav-left' =&gt;  'Left Footer Navigation',
            'footer-nav-right' =&gt;  'Right Footer Navigation'
        )
    );
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Downloads Button Homepage',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s buttons"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Locator Button Homepage',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s buttons"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Specials Button Homepage',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s buttons"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Store Locator',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Email Me',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Download Left',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Download Mid',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Download Right',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}

if ( 
    !isset( $_POST['custom_meta_box_nonce'] ) 
    || !wp_verify_nonce( $_POST['custom_meta_box_nonce'], basename(__FILE__) ) 
) 


 ?&gt;