Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/functions.php Secret

Last active Aug 29, 2015
Embed
What would you like to do?
<?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 );
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();
}
});
});
.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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.