Skip to main content
Home
The Baheyeldin Dynasty
The journey for wisdom starts with knowledge
  • Home
  • About
  • Site Map
  • Contact

Using Google AdSense with Drupal

  1. Home
  2. Resources for using Google Adsense with Drupal

By Khalid on 2005/04/07 - 19:03, last updated 2005/11/06 - 19:01

A recurring question on the Drupal.org forums is by people new to Drupal wanting to setup their site for Google AdSense. This quick guide should help with this topic.

Updates:

  • A few weeks after I wrote this article, I wrote a new Drupal Google AdSense module. You can use that for a pre-packaged solution that may be easier to configure in some cases.
  • Some of the details here (e.g. making blocks hidden for certain URL paths) are specific to Drupal 4.5. Things are easier in Drupal 4.6 and more.

Introduction

Drupal is an Open Source Content Management System that is gaining popularity fast. It is used to run lots of sites on the internet, and more and more people are using it. For more information visit the Drupal section on this web site for a quick overview.

Google AdSense is a way for web site publishers to earn some revenue by allowing Google to advertise on their web site, using targeted keywords. Google indexes your web site pages, and as visitors access them, Google tries to display ads that best matches the keywords on the specific page.

This guide assumes that you have already applied for a Google AdSense account, and that you are using Drupal 4.5 or higher.

Selecting the Ad Format

AdSense allows so many formats to be displayed. You need to select a format that fits in your site without being a distraction.

For example, if you are using blocks, then select Skyscraper format.

Select colors for the ads that will blend in your site's color scheme. You may also want to save that color scheme by a name you know (e.g. "Drupal Pushbutton") so you can use it later.

How to configure Drupal for AdSense

There are many ways of displaying Google AdSense ads in a Drupal web site. The simplest way is to display the ads in blocks. To do so, follow these steps:

  • Log in as the site administrator
  • Go to Administer -> Blocks
  • Add a block
  • Give the block a descriptive title, e.g. "Google Ads"
  • Paste the AdSense code from your account. Make sure that you paste the entire code as it is and not miss any lines.
  • Make sure that the type is PHP. If you do not see a type PHP, then add it in the Input Format.
  • Give the block a description, e.g. "Google Ads"
  • Click on "Save"

Now you have created the block, you need to enable it and position it.

  • Click on the Enabled checkbox
  • Select a weight for the block
  • Select if it is to be displayed in the right or left column.

Do not click "Save" yet. Go to the next step.

Hiding AdSense in Admin pages

Since the Administration pages are not visible to your visitors, it does not make sense to display ads on them. Moreover, you may not want to display ads on the node/add page, the edit and the outline pages.

So, in the "Path" box, enter the following regular expression, including the < and > characters:

<^(?!admin|node/add|node/\d+/edit|node/\d+/outline)>

Theme Template To Display AdSense

The above is only the simplest way you can get AdSense going, but there are many other ways to do it differently.

For example, if you want the ads to appear in the page header, or in the side of the node, or before the node title, or between the teaser and the body, you can do so.

You can even write a filter that would replace the <!--break--> tag by Google AdSense code.

However, all this involves modifying your theme to do so. If you are using a phptemplate theme, then check the node.tpl.php

Here is an example on how to change the interlaced theme to provide this. And also a discussion on how to embed AdSense in nodes.

To achieve the latter, here is what you need to do.

Say you have a phptemplate that has the following:

  <div class="content">
<?php print $content ?>
</div>

You need to change this as follows. Add the section in red, then add your Google AdSense code after it.

<div class="content">
<div style="float: right; padding: 0px; margin: 0px;
border-width: 0px 0px 10px 10px">
<!--ADD GOOGLE ADSENSE HERE-->
</div>
<?php print $content ?>
</div>

You may need to adjust the content style in your CSS file to display the rest of the node correctly.

Resources and Links

The following discussions on Drupal.org forums can also help if your answer cannot be found above:

  • Google Adsense
  • Use of Google Adsense et. al.
  • How to put a leader board Ad in Drupal
  • Issue with HTMLArea and AdSense. Note that the above regular expression for hiding the Ads in edit and add pages should take care of this.
  • Second block not displaying AdSense. This is a common question that novices ask. This is an AdSense feature, not really a Drupal problem.
  • Google AdSense (again).
  • Another Google AdSense forum discussion.
  • Another guide on how to add Javascript (including Google AdSense) to Drupal. On Bryght.
Contents: 
Drupal

Book Navigation

  • ‹ Using Drupal 4.7 regions to show/hide AdSense
  • up
  • Drupal AdSense Module: Added Section Targeting ›
  • Add comment

Comments

Criação de Sites (not verified)

Criação de Sites

Fri, 2007/04/13 - 10:23

Interest! Thanks for tips.

  • reply

Nicky (not verified)

Helpful module

Thu, 2007/06/28 - 03:08

I found this module great and helpful. It was piece of cake to implement adsense ads onto my site.
It's so easy to experiment with changing position, colors or size of ads. You don’t need to change page code, just do it from admin panel with a few clicks.
thanks...

  • reply

Anonymous (not verified)

Where is the path box, i

Tue, 2007/10/23 - 09:46

Where is the path box, i could not find it in my block page.

  • reply

Anonymous (not verified)

Issue with channels?

Thu, 2007/10/25 - 11:21

Today I gave the adsense module a try.

It works very well so far. There's just one thing I'm not sure whether it is a problem with google or not.

I want to use channels and revenue sharing.
But now the code shows my channels also for other authors.
From google point of view it must look like other people use my channels.

What happens if other people do use my channels?
Will it be a problem?
Will they get the revenue?
Will my channes be visible in their account now, too?

Hopefully someone could give an answer - otherwise I will have to remove the channels to stay on the safe side.

Thanks a lot

Werner

  • reply

Anonymous (not verified)

manage ads

Mon, 2008/01/28 - 19:05

Since Google Adsense use manage Ads, Adsense module can't applayed to sites.

Please update this module tha support Manage Ads..

  • reply

Anonymous (not verified)

Limiting Adsense to certain drupal forum pages

Fri, 2008/02/15 - 17:51

Is there a way to keep adsense off of pages which discuss sexuality and other issues that google does not allow? I have a forum for women, and in women's health they discuss this but I want adsense on the other pages...Thanks!
thinkhappy@thewomensnest.com

  • reply

Randy Robertson (not verified)

Module for 6.1?

Tue, 2008/03/18 - 01:01

Are there any plans for this module to support Drupal 6.1? I just installed Drupal for the first time and would rather not have to downgrade just to have Google ads. If not, maybe someone else has tips for another way of getting Google Ads working in 6.1.

  • reply

Khalid

Port to 6.x is planned ...

Tue, 2008/03/18 - 10:07

The port to 6.x is planned, but only after the new Google code is done in 5.x.

See 211584 and the links in the comments from there.

If people test the patch and confirm it is working, things will move faster.
--
Khalid Baheyeldin

  • reply

Anonymous (not verified)

can you update this article

Sun, 2008/06/08 - 06:00

can you update this article for the newest version? this article has lost almost all relevance to the version on drupal.org and I am having a sh!tload of problems trying to implement adsense on one of my sites. when attempting to configure "adsense: unconfigured 1" block, there is no place to copy/paste the adsense code. Yes, I have read the help, yes I have searched google, and unfortunately, your site was the first to show up.

  • reply

Anonymous (not verified)

the adsense

Sat, 2010/02/06 - 02:26

can you update this article for the newest version? this article has lost almost all relevance to the version on drupal.org and I am having a sh!tload of problems trying to implement adsense on one of my sites. when attempting to configure "adsense: unconfigured 1" block, there is no place to copy/paste the adsense code. Yes, I have read the help, yes I have searched google, and unfortunately, your site was the first to show up.

  • reply

Pages

  • 1
  • 2
  • next ›
  • last »

Current

Pandemic

  • COVID-19
  • Coronavirus

Search

Site map

Contents

  • Family
    • Khalid
    • Ancestry
    • Extended
  • Friends
  • Nokat نكت
  • Writings
    • Cooking
    • Culture
    • Science
    • History
    • Linguistics
    • Media
    • Literature
    • Politics
    • Humor
    • Terrorism
    • Business
    • Philosophy
    • Religion
    • Children
  • Technology
    • Linux
    • Arabization
    • Drupal
      • Association
    • Software
    • Internet
    • Technology in Society
    • Digital Archeology
    • NCR History
    • MidEast Internet
    • Programming
    • Saudi ISPs
    • Miscellaneous
  • Places
    • Canada
      • Weather
    • Egypt
      • Cuisine
      • Alexandria
      • E.G.C.
    • USA
    • Saudi Arabia
  • Interests
    • Astronomy
    • Fishing
    • Photography
    • Snorkeling
    • Nature
    • Photomicroscopy
  • Miscellany

In Depth

  • al-Hakim bi Amr Allah: Fatimid Caliph of Egypt الحاكم بأمر الله
  • Alexandria, Egypt
  • Arabic on the Internet
  • Articles on the history of Muslims and Arabs in the Iberian Peninsula تاريخ المسلمين و العرب في الأند
  • DIY GOTO Telescope Controller With Autoguiding and Periodic Error Correction
  • E.G.C. English Girls College in Alexandria, Egypt
  • Egyptian Cuisine, Food and Recipes مأكولات مصرية
  • George Saliba: Seeking the Origins of Modern Science?
  • Internet Scams and Fraud
  • Mistaken for an Arab or Muslim: Absurdities of being a victim in the War on Terror
  • Mistaken Identity: How some people confuse my site for others
  • One People's Terrorist Is Another People's Freedom Fighter
  • Overview of Google's Technologies
  • Photomicroscopy
  • Pseudoscience: Lots of it around ...
  • Resources for using Google Adsense with Drupal
    • Drupal Module: Google AdSense
    • Drupal: Using flexiblock to show/hide AdSense
    • Links and Resources on Google Adsense
    • Using Drupal 4.7 regions to show/hide AdSense
    • Using Google AdSense with Drupal
    • Drupal AdSense Module: Added Section Targeting
    • How To Include Drupal Comments In Section Targeting
  • Rockwood Conservation Area, Southern Ontario
  • Selected Symbolic Novels And Movies
  • Snorkeling the Red Sea near Jeddah
  • Updates and Thoughts on the Egyptian Revolution of 2011

Recent Content

Most recent articles on the site.

  • Origin Of COVID-19: Natural Spillover, Lab Leak Or Biological Weapon?
  • Kamal Salibi and the "Israel from Yemen" theory
  • How To Upgrade HomeAssistant Core In A Python Venv Using uv
  • Ancestry - Paternal Side
  • Review of Wait Water Saver For Whole House Humidifiers
more

Most Comments

Most commented on articles ...

  • Another scam via Craigslist: offering more than asking price
  • Warning to female tourists thinking of marrying Egyptians
  • Craigslist classified for used car: Cheque fraud scam
  • Winning the lottery scam email: World Cup South African lottery
  • Email Scam: BMW 5 Series car and lottery winning
more

About Khalid

Various little bits of information ...

  • Khalid Baheyeldin: brief biography
  • Presentations and Talks
  • Youtube Videos
  • GitHub Projects
  • Drupal.org Profile
  • Astrophotography @ Flickr

Sponsored Links

Your Link Ad Here

Tags

Android Mobile Ubuntu Sony OnStep OpenWRT Router Ericsson COVID-19 Rogers Coronavirus Arabic Kubuntu Home Assistant GSM Telescope tablet Spectrum Scam Python 419 Laptop Firefox DIY CPU Conspiracy Comet Balkanization backup App
More

© Copyright 1999-2025 The Baheyeldin Dynasty. All rights reserved.
You can use our content under the Terms of Use.
Please read our privacy policy before you post any information on this site.
All posted articles and comments are copyright by their owner, and reflect their own views and opinions, which may not necessarily be consistent with the views and opinions of the owners of The Baheyeldin Dynasty.

Web site developed by 2bits.com Inc.