Skip to main content

drupal 8

Add custom js into <head> programmatically Drupal 8

you can download and use this module Header and Footer Scripts

Add custom css into <head> programmatically Drupal 8

you can download and use this module Header and Footer Scripts

/**
* Implements hook_page_attachments_alter().
*
* Alter attachments (typically assets) to a page before it is rendered.
*/
function MY-MODULE-NAME_page_attachments_alter(array &$attachments) { $background_color = '#000';
  $attachments['#attached']['html_head'][] = [
  [
  '#tag' => 'style',
  '#value' => '#left_col #content { background: ' . $background_color . '; }',
  ], 'MY-MODULE-NAME'
  ];
}