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

CZ’s picture

Can not add some code to the head.

CZ’s picture

MODULNAME.libraries.yml file with: dependencies: - core/drupalSettings" required!