Easiest Way to Add Google Custom Search to WordPress Site

Many WordPress sites by default uses the normal search function. While this is a very good function, it is quite limited. It brings results in terms of post title and post content. The normal search function can also be tweaked to enable the search form to search by phrase or exact match or even custom post type. However, Google search engine surpasses the normal default search function and adds more functionality to site.
A Google search engine on your site helps to search data faster, without complicated SQL query statements. It is more like having your own Google search engine.
To add a custom Google search engine on your site, simply follow these steps.
1. To begin, you have to first deactivate any existing search forms from your site. Check your theme settings and/or the Widgets area to accomplish this.
2. The WordPress site needs a special page to display results from the search. So create a new page on your site. You may choose to call it “Search Results” or anything else. Publish the page and copy it’s full URL and protocol.
3.Next, go to the Custom Search console at Google: https://cse.google.ca/cse/all
4. Click “Add”. Type in your web site address. Since we are doing a full site search for one web site, use something like: *.example.com
5. Click “Create”. Click “Control Panel” next to “Modify your search engine”.
6. Click the “Make money” tab and turn on Monetization if you wish to earn from AdSense on your custom search engine. You can also tie your engine in with Google Analytics from the “Search and Logs” -> “Google Analytics” section.
7. From the left side, go into the “Look and feel” section and choose “Two page” and click “Save & Get Code”.
8. At the top, click “Search Results Details” and paste in the URL to your search results page created in Step #2 and click “Save”.
9. Copy the code for the search form to the clipboard, and paste it to a Text Widget. You may end up with some styling issues with the form depending on your theme. Please Google around for various CSS fixes for Google Custom Search if you find that’s the case for you.
Alternatively you can just use the Google hosted search. You can get the “Public URL” from the “Setup” section. What you can do with that is create a Custom Link in your WordPress menu called “Search”. Be sure to open the “Screen Options” tab in Menus and turn on “Link Target” so that you have the option to open this link in a new window. If you go this route, then don’t worry about the remaining steps.
10 Next, you need the code for the search results page. Click the button that says “Next: Obtain code for search results”. Copy the code to the clipboard, open your search results page that you created earlier, past the code in in “Text” view, and click Update.
Now, test your search engine! Again, you can play with the settings in the Google Custom Search Control Panel and the settings will be automatically reflected on your site.

Remember, if the form or results look a little (or a lot) off, then it’s likely just a CSS issue. There are several threads on forums that can walk you through some fixes. But you can always just use the Public URL for Google’s hosted version of your engine as described earlier, if it’s all the same to you.

Now you should be all set to let your visitors search your site using Google search.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.