• Resolved TMNR

    (@tmnr)


    Hi,

    I’ve added a search form to my navigation bar via this function:

    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;

    The problem no matter how I try the form won’t float to the right. I get the feeling that it’s a specificity issue, but don’t know exactly what’s amiss.

    Link: http://www.ajmk.lt
    *Currently there is no code for float:right; in style.css .

Viewing 1 replies (of 1 total)
  • Thread Starter TMNR

    (@tmnr)

    The function i used to add search form was lacking specificity.
    I’ve used this one instead:

    /**
     * Add a search bar to the navigation menu.
     *
     * @since Twenty Twelve 1.0
     */
    function menu_search($items){
        $search = '<li class="search">';
        $search .= '<form method="get" id="searchform" action="/">';
        $search .= '<label for="s" class="assistive-text">Search</label>';
        $search .= '<input type="text" class="field" name="s" id="s" placeholder="..." />';
        $search .= '<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />';
        $search .= '</form>';
        $search .= '</li>';
    
        return $items . $search;
    }
    add_filter('wp_nav_menu_items','menu_search');

    It sets the class of the form to .search, this way I had much more control and was able to position it.

Viewing 1 replies (of 1 total)
  • The topic ‘Float searchform to the right in navbar’ is closed to new replies.