What is the best way to add javascript to Drupal theme now that drupal_add_js is gone?

I want to use specifically jQuery ui animate, which I suspect is in Core, but I cant find out how to add it to my theme.


Use the following function in template.php of your theme.

function MYTHEME_preprocess_page(&$vars, $hook) {
  $path = drupal_get_path('theme', 'MYTHEME');
     // Render the main scripts file.
  $local_js = array(
    '#attached' => array(
      'js' => array(
        $path . '/js/scripts.js' => array(
          'group' => JS_THEME,
          'weight' => 9999),

If you'll look at seven theme you'll see a note saying that libraries should be attached in hook_page_alter. I have similar issue https://drupal.stackexchange.com/questions/106842/whats-the-proper-way-to-load-themes-libraries

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