If you have a WordPress website you may want to add a search bar to the navigation menu. You can do this without a plugin if you add this code to your functions.php file. You may want to backup your WordPress website before you make updates to the functions.php file.
/** * Empty trash automatically * * @author WPSnacks.com * @link https://www.wpsnacks.com */ function add_search_to_nav($items, $args) { ob_start(); get_search_form(); $searchform = ob_get_contents(); ob_end_clean(); $items .= '<li>' . $searchform . '</li>'; return $items; } add_filter('wp_nav_menu_items','add_search_to_nav', 10, 2);
Now if that works for you it would put a search bar in your WordPress navigation menu on there.
Leave a Reply