WordPress.org

Ready to get started?Download WordPress

Forums

Spun
Adding search bar to menu (2 posts)

  1. paperpixels
    Member
    Posted 1 year 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 1 year 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.
    http://codex.wordpress.org/Function_Reference/get_search_form

    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
    http://core.trac.wordpress.org/ticket/16541

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic