I want to "float" ads in the top right of my nodes for which Content Injector was nice enough in D6 moreover such ads convert well in my experience.

But for D7 is there any easy alternative? I know I can sub-theme and place the ads in appropriate positions.


It might not be quite as versatile, but the Block Inject module will allow you to embed adsense blocks within the node body.

  • It's in Alpha .. and too few sites using it. Wouldn't it be risky for production sites? – AgA May 23 '13 at 9:13
  • Test it, take over maintenance of Content InjectorOr or write your own. The choices are simple. – Triskelion May 23 '13 at 11:21

Without a module, just type adsense1, adsense2 anywhere in content.

(it's ok for any CMS: Drupal 7, WordPress, Joomla etc.)

First, create two or many scripts in your protected /inludes folder, with lines provides by Google Adsense (or somebody else).

adsense1.inc adsense2.inc ... adsense99.inc

// remember: just maximum 3 adsense blocks in a webpage // I've filtered any Flash movies

Second, edit /themes/$your_theme/page.tpl.php. Write this code replacing line

print render($page['content']);


if(strstr(render($page['content']),'adsense1') or strstr(render($page['content']),'adsense2')){ $pContent=explode('adsense1',render($page['content'])); $pgContent= explode('adsense2',$pContent[0]); print $pgContent[0]; if(strstr($pContent[0],'adsense2')) include('includes/adsense2.inc'); print $pgContent[1]; if(strstr(render($page['content']),'adsense1')) include('includes/adsense1.inc'); print $pContent[1]; }else{ print render($page['content']); }

Third, refresh portal performance.


P.S. www.astralia.ro


Honestly the easiest way to do ad's in Drupal 7 is with blocks. Then style your block. This is a tutorial on how to install google adsense VIA a simple block. It takes less then 3 minutes and takes no code skills. This is much simpler then adsense module or content injector module. Hope this helps you. My drupal username is alex_drupal_dev I made the video. http://youtu.be/Ti6eApzJIrY

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.