Best way of adding CSS which can be manipulated by the user via theme option panels?

One way of doing this would be to create a “CSS” file from PHP. In other words, create a file, call it something like style.css.php, and at the beginning of the file put:

<?php header("Content-type: text/css"); 

Then, link that file in the head of your theme file. Because the style.css.php file is a PHP file, anything you can do in a normal PHP file can be done in this file. As such, you can pull theme option values from the database and use them. For example:

#header{
    background: <?php echo get_option('my-header-background-color'); ?>
}

Of course, you need to get the options into the database first, but since your question didn’t address that, I won’t go into it here.

Leave a Comment