Add CSS files and JavaScript files at the bottom of a page in Drupal 7

template_preprocess_html() in template.php file. Preprocess variables for html.tpl.php
 

function themename_preprocess_html(&$variables) {

  // Add external file
  drupal_add_css('https://fonts.googleapis.com/css?family=Roboto:400,300,500,700',array('type' => 'external'));

  // Add Javascript file at the bottom of a page
  drupal_add_js('/sites/all/themes/purple/js/bootstrap.min.js', array('type' => 'file', 'scope' => 'footer', 'weight' => 10));

}

 

Tags

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
7 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.