Close Popup Search

<?php
/**
* Add Search to Menu
*
*/
function be_add_search_to_menu( $menu, $args ) {
if( 'header' == $args->theme_location )
$menu .= '<li class="menu-item search"><a href="#"><i class="icon-search"></i></a>' . get_search_form( false ) . '</li>';
return $menu;
}
add_filter( 'wp_nav_menu_items', 'be_add_search_to_menu', 10, 2 );
view raw functions.php hosted with ❤ by GitHub
jQuery(function($){
// Open Search
$('.genesis-nav-menu .menu-item.search a').click(function(e){
$('.genesis-nav-menu .search-form').css('display', 'block');
$('.genesis-nav-menu .search-form input[type="search"]').focus();
e.preventDefault();
});
// Close Search
$(document).mouseup(function (e){
var container = $('.search-form');
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});
});
view raw global.js hosted with ❤ by GitHub
.genesis-nav-menu .search-form {
background: #fff;
border-top: 4px solid #76bd22;
position: absolute;
top: 0;
right: 0;
width: 100%;
display: none;
}
.genesis-nav-menu .search-form input[type="search"] {
color: #5d5d5d;
font-size: 16px;
line-height: 30px;
outline: none;
border: none;
}
.genesis-nav-menu .search-form input[type="submit"] {
background: transparent url(images/search.jpg) no-repeat center center;
background-size: 20px 19px;
border: none;
width: 42px;
height: 50px;
position: absolute;
top: 0;
right: 0;
min-width: 0;
}
view raw style.css hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk