Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/b029efa2cc67d95f6463 to your computer and use it in GitHub Desktop.
Save billerickson/b029efa2cc67d95f6463 to your computer and use it in GitHub Desktop.
<?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