Fix Google Adsense Search and Drupal Conflict

Google Adsense internal search code does not work with Drupal sites normally. The reason is $_GET[q] conflict between both services. $_GET[q] means "current page" for Drupal and "search query" for Google. We can fix it with two easy steps.

Step 1:
Create a custom page like "websearch" etc under Drupal and add Adsense Code for results page.

Step 2:
Add this code at the top of your Drupal's index.php:

// Fix Drupal-Adsense conflict
$_GET[q] = ($_GET['cx']) ? "websearch" : $_GET[q] ;

Submitted by MVP (not verified) on Sat, 06/27/2009 - 08:02

Permalink

Thanks, it worked! That was a quick fix compared to all of the longer methods I have seen previously.

Submitted by Serg (not verified) on Thu, 10/22/2009 - 10:48

Permalink

All ingenious is simple.

Submitted by Serg (not verified) on Thu, 10/22/2009 - 11:19

Permalink

You can try to use

var googleSearchQueryString = "z";

parameter for search results. And don't forget to change this input name in search form, ofcourse.

Enjoy.