Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
Created June 14, 2021 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronsummers/65b06d3bf1387580e51b75ef88b6a589 to your computer and use it in GitHub Desktop.
Save aaronsummers/65b06d3bf1387580e51b75ef88b6a589 to your computer and use it in GitHub Desktop.
add search to menu in wordpress via functions
<?php
/**
* ANCHOR Add search box to primary menu
*/
function elab_nav_search($items, $args) {
// If this isn't the primary menu, do nothing
if ( !($args->theme_location == 'primary') ) :
return $items;
endif;
// Otherwise, add search form
return $items . '<li class="search-form">' . get_search_form(false) . '</li>';
}
add_filter('wp_nav_menu_items', 'elab_nav_search', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment