I used the free Virtue theme in a recent contract and wanted to put the WordPress search box into the primary navigation menu. That was done easily enough by putting this into the child theme functions.php file:
function add_search_form_to_menu($items, $args) { if( $args->theme_location != "primary_navigation" ) return $items; return $items . '<li class="my-nav-menu-search">' . get_search_form(false) . '</li>'; }
However, the site I was building needed a private area for members and I’d been tinkering with the WordPress Access Control Plugin (WPAC) to accomplish that. The plugin allows you to display different menus to users who are logged in and those who are not. One menu (called Top Menu) was setup by WPAC to display as the Primary Navigation for users who were not logged into WordPress. While another (I called Top Menu – Private) was setup to display to members only. Obviously I wanted the WordPress search box to display on that menu too so I had to modify the above PHP slightly to allow for the private menu. Here’s how that worked:
function add_search_form_to_menu($items, $args) { if( ($args->theme_location != "primary_navigation") && ($args->theme_location != "primary_navigation_wpac") ) return $items; return $items . '<li class="my-nav-menu-search">' . get_search_form(false) . '</li>'; }
So there you have it. How to get the WP search box to display in the primary navigation menu when using the Virtue theme, and when using the Virtue Theme with the WordPress Access Control Plugin.