Skip to content

Instantly share code, notes, and snippets.

@FutureMedia
Created June 6, 2013 17:24
Show Gist options
  • Save FutureMedia/5723249 to your computer and use it in GitHub Desktop.
Save FutureMedia/5723249 to your computer and use it in GitHub Desktop.
Add a search box in a WordPress menu that will be rendered through the native wp_nav_menu() function.
// Add a search box in the main navigation menu
function nav_search_box( $items, $args ) {
if( $args->theme_location == 'main-nav' ) {
$items .= '<li class="nav-search">
<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<input class="nav-search-field" type="search" value="' . get_search_query() . '" name="s" id="s" placeholder="Αναζήτηση" />
</form>
</li>';
return $items;
}
}
add_filter('wp_nav_menu_items','nav_search_box', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment