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 CZ on
In Drupal 7 we use drupal_add_css() or drupal_add_html_head().
This code in MODULENAME.module do not work for me:
/**
* Implements hook_page_attachments().
*/
function MODULENAME_page_attachments(array &$page) {
$description = [
'#tag' => 'script',
'#attributes' => [
'name' => 'description',
'content' => 'My script.',
],
];
$page['#attached']['html_head'][] = [$description, 'description'];
}
Comments
Not solved
Can not add some code to the head.
*.libraries.yml file required
MODULNAME.libraries.yml file with: dependencies: - core/drupalSettings" required!