In this tutorial we are going to cover the fastest way to add Google Search to a website.
I will show you a super quick way to add a Google search box on your website in under 5 minutes.
Some of you who land on this page may not be looking to add a Google search box on your site.
You may be looking to get your website pages into the Google search results. If that is you check out our guide on how to submit a sitemap to Google via the Google Search Console.
Let's get started!
Fastest Way to Add Google Search to a Website
The fastest way to add search to your site is to use a special site search from Google.
Did you know that if you type site: into the Google search bar then it will search only the site you specify.
Here is an example.
If I wanted to only search Ikea for chairs I would search:
Google search results will only display ikea.com pages, like this:
This is cool right! It allows you to show results from a single website and exclude the rest of the web. You can use this yourself to create a quick Google Search box on your site.
What we are going to do is create a search form on your site. When the user clicks search it will open a new tab with the Google Search results.
This is what the form will look like:
<inputid="query"type="search"name="q"value="site:https://ikea.com "autofocussize="50"aria-label="Search through site content">
You can see in the above code that there is ikea.com as the site search. You need to replace this with your domain name.
There is one issue with this form and it is this:
As you can see above the site:https://ikea.com text is in the search box. This is bad as the user can delete this text which will break the single-site search in Google.
What we need is to add this in the background.