Expandable search icon to the navigation bar

This is a tweaked complete version to use with Genesis Sample.
Remove the Search Widget from other Sidebars, or tweak it with css to be visible.

Source: https://sridharkatakam.com/add-expandable-search-icon-navigation-infinity-pro/

add_filter( 'wp_nav_menu_items', 'custom_nav_search', 10, 2 );
/**
* Add search box to nav menu.
*/
function custom_nav_search( $items, $args ) {

    if ( 'primary' === $args->theme_location ) { // affect only Primary Navigation Menu.
        $items .= '<li class="menu-item search">' . get_search_form( false ) . '</li>';
    }

    return $items;

}
// add dashicons
// check icons here:
//  https://developer.wordpress.org/resource/dashicons/#admin-users
add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
function load_dashicons_front_end() {
wp_enqueue_style( 'dashicons' );
}
/* menu search expandable icon */
.menu-item.search {
    margin-left: 10px;
}

@media only screen and (min-width: 960px) {
.nav-primary .genesis-nav-menu {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    align-items: center;
    -webkit-box-align: center;
    -webkit-box-pack: center;
    -ms-flex-align: center;
    -ms-flex-pack: center;
    justify-content: center;
}
}

.search .search-form {
    text-align: center;
}

.search .search-form input[type="search"] {
    position: relative;
    width: 1px;
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    background-color: transparent;
    font-family: "Open Sans", sans-serif;
    font-size: 13px;
    cursor: pointer;
    -webkit-transition: width 500ms ease, background 400ms ease;
    transition: width 500ms ease, background 400ms ease;
}

.search .search-form input[type="search"]:focus {
    width: 250px;
    outline: 0;
    background-color: #ccc;
    cursor: text;
}

.genesis-nav-menu .search input[type="submit"] {
    clip: rect(0, 0, 0, 0);
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
}

.search .search-form:before {
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);    
	color: #000;
    content: "\f179";
    font: normal 30px/1 'dashicons';
    font-size: 20px;
    position: absolute;
}

.site-container.white .search .search-form:before {
    color: #999;
}

@media only screen and (max-width: 862px) {
    .nav-primary .genesis-nav-menu {
        display: block;
    }
}

@media only screen and (max-width: 800px) {
    .menu-item.search {
        margin-bottom: 10px;
        margin-left: 0px;
    }

    .search .search-form:before {
        position: absolute;
        top: 10px;
        left: 0;
        color: #999;
        -webkit-transform: none;
        transform: none;
    }

    .search .search-form {
        text-align: left;
    }

}

Scroll to Top