As pointed by other, simply using drupal_add_js()
from a hook_preprocess_page()
implementation doesn't work. The references to JavaScript files collected through the multiple calls to drupal_add_js()
are used to generate the corresponding markup into the $scripts
variables from template_preprocess_page()
. But a theme's implementation of hook_preprocess_page()
is always called after template_preprocess_page()
. So in order to have the files added through drupal_add_js()
in your .tpl.php
file(s), you need to override the already set $scripts
variables:
function THEME_preprocess_page(&$variables)
drupal_add_js(...);
$variables['scripts'] = drupal_get_js();
}
But, you shouldn't have to add jquery.js
and drupal.js
yourself, it should already be done automatically by Drupal core. If you need to do it yourself, then something is broken on your site. You can (re-)add the files as a quick fix, but you better find the root cause of the issue as it is most likely creating other issues you haven't yet identified (or worked around without realizing it).