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

My wordpress search form (code below) appends the query string to current page only. For example if I go to http://Website/unknown-page and then use the form to search for some content the query string looks like this http://Website/unknown-page?s=Search and only searches within the current page. It should be searching from the root like this: http://Website/?s=Search

How do I fix this?

                     <form class="form-inline" role="search">
                                  <div class="form-group">
                                    <label class="sr-only" for="search">Search:</label>
                                    <input type="text" name="s" class="form-control" placeholder="Search">
                                  <button type="submit" class="btn btn-default">Submit</button>
share|improve this question
up vote 1 down vote accepted

When you omit the action attribute from the form tag, it defaults to the current URL. Give an explicit URL for the form's action to direct it to a specific URL-

<form class="form-inline" role="search" action="<?php echo home_url( '/' ); ?>">
share|improve this answer

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.