Categories
Drupal Development Resources

Adding external style sheets to your Drupal theme

Sometimes it’s best to add external CSS files through Drupal’s drupal_add_css() function. A very practical example is where we add a Google web font to a subtheme. If you’re customizing a subtheme of a complex theme like Omega and don’t want to have to create a new page.tpl.php file just to add a custom style sheet, or the additional overhead of a custom module, this is a great solution.

Here’s a handy little snippet to add an external style sheet to your Drupal 7 theme. Simply add this to your theme’s template.php file:

function yourtheme_preprocess_html(&$variables) {
  drupal_add_css(
    'https://fonts.googleapis.com/css?family=Droid+Serif:regular',
array('type' => 'external')
  );
}

 

Replace “yourtheme” with the name of the theme or subtheme you’re editing.

3 replies on “Adding external style sheets to your Drupal theme”

Good day! This post could not be written any better! Reading
this post reminds me of my old room mate! He always
kept talking about this. I will forward this page
to him. Fairly certain he will have a good read. Thank you for sharing!

I do not understand any of the answer…it states the following:

“Replace “yourtheme” with the name of the theme or subtheme you’re editing.”

But I don’t see ‘yourtheme’ anywhere? What am I missing?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.