I have read that I can add js and css file via .info files. Can I add external css and js files there as well? Eg http://somewhere.com/in_a_galaxy
2 Answers
External JS/CSS files can't be specified in the info file at all. You need to add them via hooks, typically I use THEMENAME_preprocess_page()
for things that need to be included on all pages, or you can use drupal_add_js()
in your .module
file.
And you can refer to this page. Here you can see how many ways you can add script/css files.
-
Actually it is possible in .info files ... of themes and of modules ! drupal.org/docs/7/creating-custom-modules/…– rémyCommented Sep 14, 2017 at 16:08
-
@rémy No, it is not possible for external js/css files. Take a look: drupal.org/docs/7/theming/working-with-css/… (very end "Adding external stylesheets"). The right way is to use the
drupal_add_css()
anddrupal_add_js()
functions.– 0x6d6cCommented Jan 16, 2018 at 23:15 -
-
@MichaLeuth: it is possible also in Drupal 7 to import an external CSS (I did it several times) stylesheets[all][] = file.css into the info file. Spceified here in D7 drupal.org/docs/7/creating-custom-modules/… Commented May 14, 2019 at 6:34
To add external javascript.
drupal_add_js('http://example.com/example.js', 'external');
To add external css.
drupal_add_css('https://fonts.googleapis.com/css?family=Droid+Serif:regular', 'external');