Viewing 6 replies - 1 through 6 (of 6 total)
  • I was looking for a way to do this also, and found it’s very easy to do. Just copy and past the below code into your child-theme function.php file. If you put it in the parent themes function.php you will need to replace every time you update the theme.

    /* ADD SEARCH BAR NAVIGATION BAR */
    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();
            if( $args->theme_location == 'primary' )
            $items .= '<li style="float: right; vertical-align: center;">' . $searchform . '</li>';
        return $items;
    }

    You can also add a login – logout link with the following code. Copy and past into your child-theme functions.php file.

    /* ADD LOGIN - LOGOUT LINK NAVIGATION BAR */
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    function add_login_logout_link($items, $args) {
            ob_start();
            wp_loginout('index.php');
            $loginoutlink = ob_get_contents();
            ob_end_clean();
    		if( $args->theme_location == 'primary' )
            $items .= '<li>'. $loginoutlink .'</li>';
        return $items;
    }

    Note the theme location refers to the location you want the login – logout link to go. You can also place it in the header or footer menu by replacing:

    if( $args->theme_location == 'header' )
    if( $args->theme_location == 'footer' )

    NOTE you must have one link in either menu for it to work.
    Screenshot:

    Screenshot: Click Here . . .

    Thread Starter valepalmy

    (@valepalmy)

    thank you!!!!!!!

    However, it could be a problem with the responsive menu for the search box, leading to a 404 page. Have you checked?

    No. It just disappears on my mobile devices.

    Yes the box disappears, but what about the remaining “search” link in the menu?
    I ask because I made the same change time ago (search box in menu in Leaf theme), with more or less same code as yours, and I got that problem. A visible “search” link that obviously took to a 404.
    I resolved removing responsive menu, in mobile making it appears the same way as desktop.
    So I’m just curios, I’d like to see live on mobile your search in the responsive menu.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘search box in nav bar’ is closed to new replies.