In this article, I will explain how to add google search without plugin. We see Google search in almost every WordPress site or blogs. There are many advantage to use Google Search. The benefits of using Google search are speed, users already trust Google brand, you will not have to maintain or update it and if you have adsense account, you can advertise your product on Google search result page. The default WordPress search is not much useful, that’s why every WordPress site owner look for an alternative solutions. There are many plugins for WordPress Google search implementation, but we will show you without plugin solution.
How to add WordPress Google Search
The first thing we are going to need is to generate Google search box code from Google CSE. CSE stand for Custom Search Engine. You can generate you code by adding your site name to cse.google.com.
You probably already used Google account to register your site, if not, login and add your site. Once you login, click on add button and fill the necessary information.
Add WordPress Google search page
One added your site, now you click on Get code button to copy the code we need.
Depending on your site, it will generate a unique code for you. Here is what we have generated.
var cx = ‘000132328623297516430:yfpvgjmz5b4’;
var gcse = document.createElement(‘script’);
gcse.async = true;
gcse.src = ‘https://cse.google.com/cse.js?cx=’ + cx;
var s = document.getElementsByTagName(‘script’);
By unique code, I means the code we generate is completely different from the code you generate. So make sure you are not copying our code.
Now, open your theme folder. It is located in the wp-content/theme/yourtheme. You see a searchform.php file there, open that file with notepad or any other text editor you have. Now past the code you have copied form Google CSE site. Save the file and close.
Now you can go to widget page of your WordPress site and add the search widget to side bar. Instead of default WordPress site search box, you will see the Google search. If you search anything in that field now, It will open a modal dialog and show the result.
- Google Penalty Your Site? How to Check It? - February 8, 2021
- SEO Tips :: How Social Media Activity Promotes Your Business - June 24, 2016
- Blogging Tips :: Speed Up your WordPress Site in 10 Ways - June 22, 2016