Adding search bar to menu (2 posts)

  1. paperpixels
    Posted 3 years ago #

    I am trying to add a search bar to the nav_menu, by adding this to the bottom of functions.php however it will not display.

    add_filter('wp_nav_menu_items','add_search', 10, 2);
    function add_search($items, $args)
        if( $args->theme_location == 'primary' )
            return $items . '<li>'.get_search_form().'</li>';

    Any ideas on way it seems to ignore this?

  2. paulwpxp
    Font hero
    Posted 3 years ago #

    Theme location must be primary, meaning you have to actually setup the menu to the theme location.

    Also the $echo in get_search_form( $echo ) must be false.

    But to be able to use get_search_form( false ) you need this fix which is now still in trunk.

    get_search_form() ignores $echo argument if searchform.php exists

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic