5

I want to use a Google Font on my site. I saw the @font-your-face module and installed it. Unfortunately, it does not offer the version of the 'Pacifico' font I want.

Google suggests adding the following:

<link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>

Is it possible to add it to all my Drupal page without fiddling with core code? Or is there are better way to add a font to my site?

  • I would open an issue with the font-your-face module and ask to have it added. – Letharion Apr 17 '12 at 12:04
4

Rather than using the @font-your-face module, try the Google Fonts module instead. It fetches the current font list from Google - and Pacifico is included. I've used the module in several projects - it works well and unobtrusively.

  • The module you suggest has been deprecated by it's maintainer in favor of the one that the OP is using. Google fonts is listed as "Unsupported". It doesn't seem like a good to recommend the opposite. – Letharion Apr 17 '12 at 12:02
  • That's hardly a fair knock on my answer, or something to take away points for, considering that the module was deprecated a month AFTER my answer was posted. – jmarkel Apr 17 '12 at 15:13
  • I see what you mean, but the big bold text saying the module is deprecated seems to have been added over 3 months before your answer was posted? Or am I misreading? I'm not sure about the points. Does it not make sense that an answers score changes with its usefulness? – Letharion Apr 17 '12 at 15:43
  • The last modification date for the project page was March 9, a month after my answer. And no, it doesn't make sense - things change all the time. Are you gonna go through every accepted answer here to make sure nothing has changed since the answers were posted? In the end it's not that big of a deal, but still - you shouldn't be dinging folks for old answers that were good at the time but have since been superseded... – jmarkel Apr 17 '12 at 15:58
4

You can add it by using drupal_add_css() in your template.php file's template_preprocess_html() function:

function mytheme_preprocess_html(&$variables) {
  drupal_add_css('http://fonts.googleapis.com/css?family=Pacifico', array('type' => 'external'));
}
  • Read up on the options. You likely want to set weight and/or group and/or every_page. – mpdonadio Feb 9 '12 at 20:59
  • @MPD Good point. Setting the weight one way or another might be necessary in some cases, but I'd leave that choice up to the people who are using this implementation (I haven't had the need to specify it myself this far). – Madis Feb 10 '12 at 22:39
2

The simpliest and quickest method is to add

@import url(http://fonts.googleapis.com/css?family=Fontname:400,700|Fontname2:400,700);

in one of your drupal css files. You can find this ready-generated snippet everytime you select font to use.

2

I would simply modify the html.tpl.php in your sub-theme, and add the <link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'> where you want.

I think it's clean, fast, and it won't pollute your hook_preprocess_html.

0

If you're looking to add simply add a to the html head, you can use the drupal_add_html_head() function in hook_page_alter(). I like this technique as it means one less module for a complex site. See this article for an example.

0

90% of all time, I add the following into my page.tpl.php file.

  drupal_add_css('http://fonts.googleapis.com/css?family=Lato:400', array('type' => 'external'));

For greater control, use

$element = array(
  '#tag' => 'link',
  '#attributes' => array(
    'href' => 'http://fonts.googleapis.com/css?family=Lato:400', 
    'rel' => 'stylesheet',
    'type' => 'text/css',
  ),
);
drupal_add_html_head($element, 'lato'); // You can change the word lato.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.