Google Adsense Code Drupal Websites

Simply add Google Adsense Code in Drupal Websites:

Google Adsense Code Drupal Websites: Well, wondering around Drupal core’s rigid text filtering techniques, it seems almost impossible to insert Google Adsense code directly into the segments of a Drupal based website. I found this issue as well and there was a plethora of module based solutions; a bit too complicated processes.  I tried several and got stuck for one or the other reason. My struggle led me to the below solutions as finality:

Solution One: create blocks to display adsense ads in Drupal based websites

  1. Create a new block in your Drupal Core from the Structure >>Blocks >>Ad Block
New Block

New Block

  1. Give your block a title, we give it the title “myads”

Block Title

  1. Add description to your blog:

Block Description

  1. Set your Text format to php code:

Block Format

  1. Put your ad code inside.
  2. Set the location where you want this block to appear. We have set it to the first sidebar.
  3. You can see the output.


Solution Two: using “PHP include” to display adsense ads on your Drupal site.

If your ad still does not show up on Drupal, you may follow the below method:

  1. Create a blank php file named ad.php.
  2. Put your adsense code inside it.
  3. Put the file onto your hosting server root folder; we put it inside includes folder.
  4. Create a new block.
  5. Set the text format to “php code”
  6. Use php include command:

<?php include(“includes/ad.php”); ?>

  1. Save your block and display it wherever you want on your website.
  2. You can see that your website displays ads properly without any third party ad modules. 


Leave a Reply