0

I'm using the follow code in my functions.php to add a search box to my primary nav menu -

add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2);
        function add_search_box_to_menu( $items, $args ) {
            if( $args->theme_location == 'primary' )
                return $items."<li class='menu-header-search'><form action='search.php' id='searchform' method='get'><input type='text' name='s' id='s' placeholder='Search'></form></li>";

            return $items;
        }

The form adds to the nav menu ok, but any search attempt leads to a 404 message. What have I missed?

1

Don't submit directly to search.php. WordPress probably will not know what to do with that. You will have the same issue submitting directly to any theme file.

WordPress should pick up on the s parameter and process the search correctly if you just leave out the action attribute like so:

<form id='searchform' method='get'>

Untested, but I am fairly confident.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.