My theme’s style.css file is quickly growing into something monstrous. So I would like to break it apart into easy to manage, custom style sheets that control specific elements, such as type.css, color.css, graphics.css, etc. My question is:

How do I add (import) custom style sheets to my themes template.php file.

Is that a PHP function? What would that code look like?

All comments and suggestions would be greatly appreciated.

Comments

creazion_dev’s picture

Hi syquest,

to import your own styles into your theme put the following code into your template.php:

<?php
  theme_add_style
('type.css', $media = 'all');
 
theme_add_style('color.css', $media = 'all');
 
theme_add_style('graphics.css', $media = 'all');
?>

and it should work.

---------------------------------------------
last projects: www.happy-faces.de - www.3p-consulting.com

syquest’s picture

Danke schön for your suggestion, but it isn't working for me.

When I include the style h2 color: red in style.css the style applies to the output: all h2s are red.

However if I...

(1) remove that style from style.css;
(2) place it in a new file, type.css;
(3) then add the PHP code, as you suggest above, to template.php

... the resulting output contains blue h2s, their default color. What am I doing wrong?

syquest’s picture

I had to add a path...

<?php
  theme_add_style
('/themes/my_theme/type.css', $media = 'all');
?>

...and now it works like a charm.