Skip to main content

How to add advertising

April 28, 2010 by Steve

Websites should look nice. Site designers go to a lot of trouble to make websites pretty and functional at the same time. People should enjoy looking at the site, not wince because everything they look at is blinking at them and asking for money. I much prefer the internet without advertising, but the simple fact is that hosting a site, even with the cheapest hosting I could find, still costs something. With that in mind, I decided to include some ads on the site. Sorry about that.

My goals are modest, I hope to make enough to pay for the site hosting, so I do not want to pack ads in every open spot like some sites do. I want the ads to stay around the edges and not distract from the look of the theme. I decided to go with three different sources for advertising. Two involved custom blocks, and one has a module involved.

Create a custom block - Many ad providers will give you the HTML code needed for their ad, which you just need to copy and paste into your website. With Drupal, it is very convenient to put those into blocks, which you can then put into your layout where you want. This is what I did for the 1&1 and Amazon ads.

Site Building > Blocks > Add Block will give you a form to fill out for your new block. The "Description" will be the name used by Drupal when showing you the block layout menu, so use something you can remember, like "Amazon 728px wide". Paste the code from your ad provider into the "block body" area. Don't forget to open up the Input Format area and make sure it is set to "Full HTML". Filtered HTML will strip out the iframe tag that most of these ads use, and it will not show on your page. Save your new block, repeat as needed.

Setup the Google AdSense module - The AdSense module works hand in hand with the Google ad servers to make it pretty straightforward to set up your ads.

First, go get a Google AdSense account. If you do not have one already, you will need to do this after your site is running, since they will review your site before giving you an active account.

After you download and install the AdSense module, you will see seven new sub-modules on your admin page. You need to turn on the "AdSense core" and "Managed ads" modules, just leave the rest alone. Go to the module admin page for the AdSense module and put in the publisher ID that you got from Google. That's all you need to do here.

Head over to Site Building > Blocks > Add Block again. Now you will have three unconfigured Google ad blocks available, numbered 0, 1, and 2. (That's how you know it was written by software engineers, they start counting at zero.) Choose one block and click on "configure".

From here out, you'll need to have your Google AdSense account open in one browser tab and your blocks configuration in another. Create a new ad on the Google site. Rather than copying down all the HTML code they give you, note the ad ID number associated with your new ad. (They have made it so that you can't easily copy that from the HTML, so save that and go back to the list of ads, copy the ID number from there.) Paste that ID number into the block configuration on your Drupal page. Change the name to something you'll remember later, like "Skyscraper 160px" and save that block. You're done, the module will take care of the rest of it in the background. Repeat as needed, remembering that the AdSense terms of service limit the number of AdSense ads that any one page may display.

Now you've got your new ad blocks, use the Site Building > Blocks page to place them where you like on the page, remembering to save your changes as you go to make sure that the layout is what you want.

@stevew99999

  • @rosamundlannin I make regular chili but use that veggie crumble meat substitute stuff. 4 years 50 weeks ago
  • @Snarky_Geek Since I was awake at 4:30 this morning, and finally just gave up and went to work around 5:45, I feel your pain. 4 years 51 weeks ago
  • One of the Chicago office dogs really wants to play this morning @the_nerdery, keeps bringing toys over to try to start something. 5 years 7 weeks ago

Premium Drupal Themes by Adaptivethemes