Custom Google Search Provider with an Open-Search Auto Discovery for a WordPress Site

image Since I spent the last half an hour doing this for one of the student WordPress websites (NCKU IIMBA Student Council), might as well explain how it’s been done. Shouldn’t take anyone more than 20 minutes.

First, you’ll need to make a Google Custom Search. I’ve made one for the students, and you can take a quick look at the NCKU IIMBA student search and what a general results page would look like. It shows you all results but emphasizes a few websites that are important for students studying in NCKU-Tainan. A few possible search refinements were added (“Tainan”, “NCKU”, “Taiwan”, “IIMBA”).

Next step it to integrate the Google Custom Search to the WordPress blog. There are endless guides out there that explain it. Phutse does a good job with “How to incorporate Google Custom Search engine with Adsense into your WordPress blog" as does DoshDosh with “How to Set up Google Custom Search for Your Website and Make Money“. I’ve also added a Text widget on the side with the Custom search Javascript code. Width can be adjusted by playing with the Google Java code provided.

The next step was to make an auto-discovery OpenSearch XML file, so that the students can add this search to the browsers (Internet Explorer 7 and above,  Firefox 2 and above). Haacked does a good job explaining that one with “Integrate Your Custom Search Engine With The Browser”.

My XML file ended up looking like this :

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription
    xmlns="http://a9.com/-/spec/opensearch/1.1/">
  <ShortName>NCKU IIMBA Search</ShortName>
  <Tags>NCKU IIMBA INCKU students student </Tags>
  <Description>
    NCKU IIMBA search
  </Description>
  <Url type="text/html"
    template="http://iim.incku.com/search_result?cx=009510974112669170466%3Aoev8ebat7gw&amp;cof=FORID%3A11&amp;ie=UTF-8&amp;q={searchTerms}&amp;sa=Search&amp;" />
</OpenSearchDescription>

and that’s it, we’re done.

  • http://www.beyondtaiwan.com Chris

    Thanks, I didn't know you could do this. I've been wanting to add a search to my site as well.

    Cheers!

  • aruna

    Great job, i got the idea, thanks lot !!!! :)