WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 '14 at 17:40

Your Answer


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.