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

Anonymous (not verified)

great page BUT......in the

Thu, 2010/02/25 - 10:29

great page BUT......in the instructions above on "How to configure Drupal for AdSense" it states

Paste the AdSense code from your account. Make sure that you paste the entire code....

my question is.....WHERE???? i dont see any option to paste php code here on the blocks page. could someone please help me out on this one. there is no option for input format either

  • reply

rmakrishna (not verified)

google adsense

Wed, 2010/07/07 - 08:23

hi sir i want to add google adsense to my website could you please tell me where i have to paste the google addsense code.and how to add google addsense in the content block rightside for example

Cinemachances.com is a portal which highlights
the arts and skills of the artists who want
to enter into Telugu Film Industry (Tollywood)
over Internet so that prospective producers
and directors who are in immediate need and
search of the artists can get quick information

the remining place after the content i want to place addsense could u please help me
thanks a lot

  • reply

Pages

  • « first
  • ‹ previous
  • 1
  • 2

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.

  • Evidence Against Ivermectin Efficacy For COVID-19
  • 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
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.