How to automatically add a search field to your navigation menu | Wordpress


/ Published in: PHP
Save to your folder(s)

Place snippet in functions.php


Copy this code and paste it in your HTML
  1. add_filter('wp_nav_menu_items','add_search_box', 10, 2);
  2. function add_search_box($items, $args) {
  3.  
  4. get_search_form();
  5. $searchform = ob_get_contents();
  6.  
  7. $items .= '<li>' . $searchform . '</li>';
  8.  
  9. return $items;
  10. }

URL: http://www.wprecipes.com/how-to-automatically-add-a-search-field-to-your-navigation-menu

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.