Adding a JavaScript file

Andrew picture Andrew · Apr 1, 2010 · Viewed 15.4k times · Source

I'm trying to insert reference to the Javascript file in the header by using drupal_add_js(). I placed this line inside the template preprocess function in template.php. The result that the code is not working at all: There is no script link in output as it should be. Can anyone tell me what am I doing wrong?

function phptemplate_preprocess_page(&$vars) {
    $url = drupal_get_path("theme","mysite");  
    drupal_add_js($url."/jquery.js");  
    drupal_add_js($url."/drupal.js");  

.....

Answer

marcvangend picture marcvangend · Apr 2, 2010

Even easier, Javascript that needs to be loaded on all pages can be added in the theme's .info file. See http://drupal.org/node/171205#scripts.