Skip to content

Instantly share code, notes, and snippets.

@brettsmason
Last active June 18, 2018 11:53
Show Gist options
  • Save brettsmason/227a6c0a6fd1879f5abc3f3d1d52492a to your computer and use it in GitHub Desktop.
Save brettsmason/227a6c0a6fd1879f5abc3f3d1d52492a to your computer and use it in GitHub Desktop.
Add search form to a menu #PHP #WordPress
function primary_menu_search_form( $items, $args ) {
if ( $args->theme_location == 'primary' ) {
$search = '<li class="menu__item menu__item--search">' . get_search_form( false ) . '</li>';
return $items . $search;
}
}
add_filter( 'wp_nav_menu_items', __NAMESPACE__ . '\primary_menu_search_form', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment