Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Last active January 12, 2018 12:16
Show Gist options
  • Save everaldomatias/b9a67e3e31f676bc857134bdd71801fc to your computer and use it in GitHub Desktop.
Save everaldomatias/b9a67e3e31f676bc857134bdd71801fc to your computer and use it in GitHub Desktop.
Add search field in nav menu WP
/**
* Add search field in nav menu WP.
* @author Everaldo Matias <matiaseveraldo@gmail.com>
* @link https://developer.wordpress.org/reference/functions/get_search_form/
*/
add_filter( 'wp_nav_menu_items', 'add_search_in_nav' );
function add_search_in_nav() {
// If this isn't the responsive-menu, do nothing.
if ( ! ( $args->theme_location == 'responsive-menu' ) )
return $items;
// Otherwise, add search form in initial nav.
return '<li class="search-in-nav">' . get_search_form( false ) . '</li>' . $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment