// Add search bar show/hide functionality for main menu
$('.search-toggle').click( function() {
$(".nav-search").slideToggle('slow', function(){
$(".search-toggle").toggleClass('active');
});
});
add_filter( 'wp_nav_menu_items', __NAMESPACE__ . '\add_navigation_items', 10, 2 );
/**
* Add extra menu item for search
*
* @since 1.0.0
*
* @param $menu
* @param $args
*
* @return string
*/
function add_navigation_items( $menu, $args ){
// make sure we are in the primary menu
if ( 'primary' == $args->theme_location ) {
$menu .= '</ul><ul class="primary-nav-icons">';
$menu .= '<div class="search-toggle"><i class="fa fa-search"></i></div>';
return $menu;
}
}
add_action ( 'widgets_init', __NAMESPACE__ . '\register_menu_widgets', 10 );
/**
* Register menu widget areas
*
* @since 1.0.0
*
* @return void
*/
function register_menu_widgets() {
genesis_register_sidebar( array(
'id' => 'nav-search',
'name' => __( 'Navigation Search', CHILD_TEXT_DOMAIN ),
'description' => __( 'This appears when you click the Search icon in the menu', CHILD_TEXT_DOMAIN ),
) );
}
add_action ( 'genesis_after_header', __NAMESPACE__ . '\position_menu_widgets', 12 );
/**
* Position widget area that holds the menu's search box
*
* @since 1.0.0
*
* @return void
*/
function position_menu_widgets () {
genesis_widget_area( 'nav-search', array(
'before' => '<div class="nav-search"><div class="wrap">',
'after' => '</div></div>',
) );
}