Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
That was it, thank you. –  user1255049 Feb 20 at 17:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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