For any WordPress website, whether a popular one or a newly-launched one, a conspicuous search box is pretty essential. After all, readers need it to search for the specific information by entering a related query. This feature can improve the usability of your site to the largest extent, thus guarantee a good reading experience to your visitors effectively.
Since October 24, 2006, Google has released a powerful and useful tool named as Google Custom Search Engine, which allows webmasters to attach a search box to their sites with ease. In the following, we’d like to show you how to integrate the WordPress site with Google search box.
Create a Custom Search
In the very beginning, you need a Google account to sign in the homepage of Google Custom Search Engine. If you don’t have one, it is time to carry out a registration process. After entering the right page, click on the Create a Custom Search Engine button.
Then, you can be redirected to the creation page that requires you to fill out the name and URL of your site. In general, it applies for any of the following.
- Individual pages: www.example.com/page.html
- Entire site: www.mysite.com/*
- Parts of site: www.example.com/docs/* or www.example.com/docs/
- Entire domain: *.example.com
The new search engine will be automatically named according to the URL selected, and you can change it at any time you want.
While finishing those blank spaces, simply click the Create button.
If you have already used this tool to create Google custom search for another website, you will be directly linked to your previous creation like the image showed below. At this time, you need to click the New Search Engine option in the left bar to set up a new one.
Next, describe your search engine by deciding the name, adding a short description, selecting the keywords, and choosing the language in the Edit Search Engine option.
Customize the Search Box
To make your search box eye-catching in your website, you need to customize the look and feel carefully. In the Edit Search Engine < Look and Feel section, you can decide the layout, theme, font, and color freely according to your preference.
After deciding the appearance of the search box, simply hit the Save & Get Code button to be redirected the webpage containing the code needed to add the Goggle search box to WordPress.
See the coding example showed in below.
Add Search Box to Website
At present, you have completely created a custom search engine, and it’s time to add it into your WordPress website. Find the searchform.php via Appearance -> Editor. Open the file and paste into the code copying from the custom search.
However, some themes don’t include the searchform.php File. In this case, you should create it by yourself. Create a text file and save it as searchform.php, then upload it to the theme directory by using FTP client.
After that, you need to drag and drop the search widget into the sidebar via Appearance -> Widgets.
In addition to the method introduced above, you can also make use of some powerful WordPress plugins like WP Google Search and WordPress Google Search. You only need to download and install one of these tools, and activate them in WordPress. Then, the Google Search widget can be created automatically.