Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tresero on
Adding the
header: true
Doesn't appear to work, at least on a Bartik subtheme. It won't output anything. If I take that out, it loads the file in the footer as expected. This is a facebook pixel and needs to be in the head section.
This is the code in the theme.libraries.yml
facebook:
header: true
js:
js/facebook-pixel.js: {}
I have no idea why this doesn't work.
Comments
came to know..
How to add external js?
Hi Nitin,
How to add External js?
e.g.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jcarousel/0.3.5/jquery.jcarousel.min.js"></script>
I want this in my head section \
Thanks,
Sachin
Could you try this ?
This thread might be helpful.
key is array element at position 1.
While adding key keep in mind it should be string value.
--
Yogesh Kushwaha
hello,
hello,
I had the same problem ans i solve it with
https://www.drupal.org/docs/8/theming-drupal-8/adding-stylesheets-css-an...
in section "Asset loading order"
we need to add like this
In the yourtheme.libraries.yml we need to create a library like below
library-name:
header: true
js:
https://external_js_url: { type: external,attributes: { async: true } }
and in the theme.info.yml we need to add this library then it will automatically comes in head tag, if we remove header:true it will come in body tag
This works
Thank you!!!
Perhaps try this module
Perhaps try this module
https://www.drupal.org/project/header_and_footer_scripts
--
www.zyxware.com
Got the same question here.
Got the same question here. Please, notify me when you find the solution!
Kind regards,
Katrina Lehmann
Loading JavaScript via header or footer
This is your best bet if you don’t want to rely on an additional module to do it.
https://www.drupal.org/docs/theming-drupal/adding-stylesheets-css-and-ja...
See this section for loading in the header or footer, the footer is recommended if it doesn’t need to load before other scripts.
https://www.drupal.org/docs/theming-drupal/adding-stylesheets-css-and-ja...