patric-boehner
7/2/2016 - 10:46 PM

Filter the menu to add search bar and widget area as line item in genesis

Filter the menu to add search bar and widget area as line item in genesis

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

//* Filter the header menu to add search and social
https://www.petersenmediagroup.com/adding-simple-social-icons-search-form-genesis-menu/

add_filter( 'wp_nav_menu_items', 'pb_search_social_menu_extras', 10, 2 );
function pb_search_social_menu_extras( $menu, stdClass $args ){

	//* Add the extras to the header-menu
	if ( 'header-menu' != $args->theme_location )
		return $menu;

	// Output buffer the search form
	ob_start();
	get_search_form();
	$search = ob_get_clean();

	// Output buffer the widget area
	ob_start();
	genesis_widget_area('before-header');
	$social = ob_get_clean();

	// Setup sturcture
	$menu .= '<li class="right search">' . $search . '</li>';
	$menu .= '<li class="right social">' . $social . '</li>';

	// Return the menu
	return $menu;

}