How to add Google custom search into Magento

Maybe, this is a popular article which you can find easily by searching in Google but in my article, I will show you how to integrate Google custom search into Magento search box. The result will show in a Magento cms page. It brings customer a feeling that is a search feature integrated for your website. This is a requirement from one of our clients for his website which you can visit at this URL:

Step 1: Create a search result page

We will create a CMS page which will show search result from Google custom search. I assume that all of you already know how to create CMS page. Let's choose 'search' for url key of this page. In the main content, we need to add following code:

Step 2: Customize Magento search box

The template for Magento search box can be found at app/design/frontend/base/default/template/catalogsearch/ We will customize this so it will call the result page which we created above. Change this form:

Change into following code:

You can compare to find out what needs to be changed for your code. The most important parameters in this form are:
- cref: The url of your CSE specification
- q: The query box
- action field: The URL you wish to host the results at (in this example we use a CMS page
In CSE xml file, you have to define which site for the search to search from. They are called annotations. You can have a look at this file to see how this xml file is formatted: You can also refer to following URLs to learn about annotations definition.
If you have any question about this, comments will be helpful.

5 thoughts on “How to add Google custom search into Magento”

5 Responses to How to add Google custom search into Magento

  • Michael Beyer
    Michael Beyer on July 26, 2012 at 5:17 pm said:

    Your Care & Heal link doesn't work.

    Thanks for interesting Post.

  • Neo

    Thank you, Michael. I fixed that.

  • lei

    is it possible that i can embed a specific search from google.. like google with recipe

  • Neo

    @lei: You can. In cref_cse.xml file, you can define the source to search from. Put some websites about recipe there and you will get the result.

  • Alma Castellanos
    Alma Castellanos on April 16, 2014 at 4:47 am said:

    Hi Neo,
    I'm just trying if the issue posting in your site is only for Safari, I'm using now Firefox. If you see this post if, of course, because it worked if not I'll send you and email.
    What happened in Safari is that you cannot see the captcha, so when you submit the page is telling you that is required to fill the captcha, when you come back, you can see the captcha but not the email box, so you never have the complete form.
    I don't know if this is due of a specific configuration of my browser (I only have blocked the pop up windows). I hope this will help you.
    Thank you for your response of my ticket and for your interest,