0

I want to add an external file to the header. To that affect I copied what others have done and used drupal_add_js();:

  drupal_add_js('somefile.js', [
    'type' => 'external',
    'scope' => 'header',
    'defer' => TRUE,
  ]);

But the link still appears in the footer. Of course I've cleared cache and theme registry, but no changes.

How can I add the file to <head>?

5
  • Check if your active theme has the region header defined in its info file Mar 1, 2019 at 1:58
  • @IsmailCherri, yes it does: regions[header] = Header
    – MeltingDog
    Mar 1, 2019 at 2:06
  • Are you sure no other module or theme is adding that same file to the footer somewhere? I'd use grep -rn 'somefile' /var/www/html/my-drupal-site/ to see if anybody else is trying to include it. Mar 1, 2019 at 3:04
  • Check your theme templates. Does your theme have a custom html.tpl.php? If so, you may check where it is printing the $scripts variable (<?php print $scripts; ?>). Is it located within your template's header, or at the bottom of your file? Mar 1, 2019 at 13:58
  • Have you tried setting the scope in a hook_js_alter() implementation? api.drupal.org/api/drupal/modules%21system%21system.api.php/… Mar 2, 2019 at 19:51

0

Your Answer

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

Browse other questions tagged or ask your own question.