Take the 2-minute tour ×

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


