Adding external CSS files to your site head using 'drupal_add_css'

If you need to add an external CSS file to your D7 site, you could in theory just add it to the default html.tpl.php template. Sometimes this isn't ideal - like when using sub-themes - in this instance you can add your CSS via the template.php file. 
One particular scenario where this was useful was on a multisite setup, where I wanted to one generic css file included on all sites even though they each had their own Omega sub-theme

To inlcude external CSS in your template.php file use this:

function mytheme_preprocess_html(&$variables) {
  drupal_add_css('', array('type' => 'external'));

BTW. If you want to add a new 'internal' CSS file to your site you should do it via your theme .info file - see this post on adding CSS the correct way. This will ensure that it's available for aggregation and optimisation with the site Performance settings.


Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +10 years.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.