I want to integrate infolink code. Finally I copied this code just before print $closure in page.tpl.php file at the bottom to make it work:

<script type="text/javascript">
   var infolink_pid = 326015;
   var infolink_wsid = 3;
<script type="text/javascript" src="http://resources.infolinks.com/js/infolinks_main.js"></script>

But why this code does not work when placed in the same place?

global $theme;

drupal_add_js($js_fl_path, 'theme', 'footer');

I'm using a subthemed Garland in sites/all/themes/ui_garland.

1 Answer 1


If you had had that code directly in the page.tpl.php its normal, because your page is rendered in the same time as you try to add the JavaScript.

You should add your code in one file, at the root of your theme called template.php.

  • Can you please be specific? Will simply placing code in template.php reflect in the site?
    – AgA
    Oct 17, 2011 at 6:51
  • Yes, if you had this code directly in the file template.php it will works.
    – yvan
    Oct 17, 2011 at 6:53
  • Yes that's right, because when you place drupal_add_js directly in page.tpl, it's not rendered anymore because the JS array must be set before any render is done and drupal access page.tpl when he begins rendering so it's too late to put a new js in the array..I hope I am clear :)
    – Mika A.
    Oct 17, 2011 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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