Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a Google search box to my website?

I am trying to add a Google search box to my own website. I would like it to search Google itself, not my site. There was some code I had that use to work, but no longer does:

<form method="get" action="https://www.google.com/search"> <input type="text" name="g" size="31" value=""> </form> 

When I try making a search, it just directs to the Google homepage. Well, actually it directs here: https://www.google.com/webhp

Does anyone have a different solution? What am I doing wrong?

like image 240
wahle509 Avatar asked Dec 11 '12 15:12

wahle509


People also ask

Can I use Google search on my website?

Check if your website appears on Google SearchGo to google.com. In the search box, type site: followed by your website address. If your website appears, you're all set. If not, submit your website directly to Google using Google Search Console.


2 Answers

Sorry for replying on an older question, but I would like to clarify the last question.

You use a "get" method for your form. When the name of your input-field is "g", it will make a URL like this:

https://www.google.com/search?g=[value from input-field] 

But when you search with google, you notice the following URL:

https://www.google.nl/search?q=google+search+bar 

Google uses the "q" Querystring variable as it's search-query. Therefor, renaming your field from "g" to "q" solved the problem.

like image 197
Cryothic Avatar answered Sep 28 '22 09:09

Cryothic


This is one of the way to add google site search to websites:

<form action="https://www.google.com/search" class="searchform" method="get" name="searchform" target="_blank">  <input name="sitesearch" type="hidden" value="example.com">  <input autocomplete="on" class="form-control search" name="q" placeholder="Search in example.com" required="required"  type="text">  <button class="button" type="submit">Search</button>  </form>
like image 25
sansan Avatar answered Sep 28 '22 10:09

sansan