1

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">
                                  </div>
                                  <button type="submit" class="btn btn-default">Submit</button>
                            </form>

1 Answer 1

1

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( '/' ); ?>">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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