Link to home
Start Free TrialLog in
Avatar of Solenthaler
Solenthaler

asked on

Drupal 7: Include a referenz to webfont CSS in HTML head

Need to implement some special fonts onto my Drupal WebSite. Therefore need a link to a CSS File in the Main HTML-File.
How is this done?
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Place the stylesheet in the css folder inside your theme folder. Open the template.php file from the theme folder and add:
$theme_path = base_path() . drupal_get_path('theme','your_theme_folder_name');
$css_path = $theme_path . 'css/your_stylesheet.css';
drupal_add_css($css_path);

Open in new window

Change the folder and file name.
Avatar of Solenthaler
Solenthaler

ASKER

Done as you stated. It's not working. The font's are not recognized. I do have my own template done with artisteer.
Can you verify that the stylesheet is now referenced in the head of the rendered page?

Are there any console errors regarding fonts not found? Perhaps the path to the font files relative to the location of the stylesheet is not correct.
I'm new to Drupal and have probs to find an entry point. In my Drupal installation there is a"/themes" path in root and a "/sites/all/themes/my_art_drupal_theme/template.php." Here i included the following Code:
$css_path = '/MyFontsWebfontsKit.css';
echo "css_path: " .$css_path;
drupal_add_css($css_path);
-> the echo: css_path: /MyFontsWebfontsKit.css
But the MyFontsWebfontKit.css is not not icluded.
The "sites/all/themes" is the correct folder.

Place your stylesheet in the css folder inside of the my_art_drupal_theme folder. Create the css folder if it's not already there.

You need to include the base path and path to the theme folder or the stylesheet will not be found and included.
$theme_path = base_path() . drupal_get_path('theme', 'my_art_drupal_theme');
$css_path = $theme_path . 'css/MyFontsWebfontsKit.css';
drupal_add_css($css_path);

Open in new window

The fonts may still not show up but check the view source of the rendered page to see if the stylesheet was included. The paths to the font files may need to be adjusted in the stylesheet.
Code at top of "/sites/all/themes/drupal_v1/template.php "
<?php
// $Id
require_once("common_methods.php");

$theme_path = base_path() . drupal_get_path('theme', 'drupal_v1');
$css_path = $theme_path . '/MyFontsWebfontsKit.css';
drupal_add_css($css_path);

echo "css_path: " .$css_path;
--------------------------------------------
php echo: $css_path-> /sites/all/themes/drupal_v1/MyFontsWebfontsKit.css
-> looks good!
--------------------------------------------
But the stylesheet "MyFontsWebfontsKit.css" is still not included (all others are).

With other CMS'es (eg Joomla) the MyWebfontKit works like a charm
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial