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] ; 

Comments

Added to DrupalSightings.com

Awesome!

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

Good

All ingenious is simple.

Google's solution

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.

How do I create a custom webpage in Drupal 5

Have been trying to do this since I've seen the solution, with no success...... :-(

adsense is not showing

Does this fix works for adsense 7.x dev? which was enabled last march of this year?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.