Skip to content

Instantly share code, notes, and snippets.

@SiGaCode
Created October 19, 2016 10:57
Show Gist options
  • Save SiGaCode/266f0c64cf576734119f4d4e148786e3 to your computer and use it in GitHub Desktop.
Save SiGaCode/266f0c64cf576734119f4d4e148786e3 to your computer and use it in GitHub Desktop.
Add animated search to primary menu.
add_filter( 'wp_nav_menu_items', 'theme_menu_extras', 10, 2 );
/**
* Filter menu items to append a search form.
*
* @param string $menu HTML string of list items.
* @param stdClass $args Menu arguments.
*
* @return string Amended HTML string of list items.
*/
function theme_menu_extras( $menu, $args ) {
if ( 'primary' !== $args->theme_location )
return $menu;
$menu .= '<li class="search"><a id="main-nav-search-link" class="icon-search"></a><div class="search-div">' . get_search_form( false ) . '</div></li>';
return $menu;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment