For a more technical turn on this blog, I thought I’d give you a few pointers as to how I managed to get GCS to work on my current project.

First, have you created your search engine yet? Make sure to think thoroughly on which sites you want to add to which search engine, and have a look at the formatting tips for the URLs.

Then, and this is as it is on 01/11/11, go to “Look and Feel” and choose “Results only”:

<div id="cse" style="width: 100%;">Loading</div>
<script src="//" type="text/javascript"></script>
<script type="text/javascript">
function parseQueryFromUrl () {
var queryParamName = "q";
var search =;
var parts = search.split('&');
for (var i = 0; i < parts.length; i++) {
var keyvaluepair = parts[i].split('=');
if (decodeURIComponent(keyvaluepair[0]) == queryParamName) {
return decodeURIComponent(keyvaluepair[1].replace(/+/g, ' '));
return '';
var _gaq = _gaq || [];
function _trackQuery(control, searcher, query) {
var loc = document.location;
var url = [
loc.pathname,, ? '&' : '?',
_gaq.push(["_trackPageview", url.join('')]);
google.load('search', '1', {language : 'fr'});
google.setOnLoadCallback(function() {
var customSearchControl = new'YOUR_CODE_FROM_CSE');
customSearchControl.setSearchStartingCallback(null, _trackQuery);
var options = new;
customSearchControl.draw('cse', options);
var queryFromUrl = parseQueryFromUrl();
if (queryFromUrl) {
}, true);
<link rel="stylesheet" href="//" type="text/css" />

Then copy this text to a WordPress-Page of your choosing (don’t forget to change the Analytics-number!!), and what matters is the Permalink you give it. would be nice, but it could also be /google/ or anything else for that matter, just make sure you remember :).

You can at this stage actually already try to see if the Search works by going to your page, in my example it would be and add a ?q=searchterm to it, giving you

The idea now would be to create a template specifically for the search results. I will not go into details for this, but if you search for page template wordpress on google, you should find hundreds of tutorials. Remove anything that isn’t useful, and then go back to editing your WordPress-Page and make sure you use the new Template.

And then, a neat feature is to create a file called searchform.php into which you only paste the following code:

<form method="get" id="searchform" action="/search/">
<label for="q" class="assistive-text">Recherche</label>
<input type="text" class="field" name="q" id="q"/>
<input type="submit" class="submit" id="searchsubmit"/ value="Recherche">

and upload it to your wordpress-template’s main directory. This will be your new Search Widget then, and replace the one that comes with WordPress, and you can put it pretty much anywhere you want on your site where you have widget-areas defined. Play with classes to make it look the way you want, and make sure to change the form’s action to your wordpress-permalink. Not the whole link though, only the bit – as in this example – that comes after

I hope this works for you guys, it cost me quite a bit of time to figure it all out, whilst actually, it was very simple from the beginning…