Advertisement
grappler

functions.php - add search to main menu

Oct 20th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2.  
  3. // Exit if accessed directly
  4. if ( !defined('ABSPATH')) exit;
  5.  
  6. /**
  7.  *
  8.  * Add search to main menu
  9.  *
  10.  */
  11.     add_filter('wp_nav_menu_items','add_search_box', 10, 2);
  12.     function add_search_box($items, $args) {
  13.         if($args->theme_location == 'header-menu') {
  14.             ob_start();
  15.             get_search_form();
  16.             $searchform = ob_get_contents();
  17.             ob_end_clean();
  18.      
  19.             return $items .= '<li id="searchform-item">' . $searchform . '</li>';
  20.         }
  21.         return $items;
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement