views:

30

answers:

2

I have created a theme where I already have a custom options page where I let the user set text for footer, twitter user and some other things and that works well. Now i'd like to add the functionality of letting the user that installed the theme select which font that should be used for content on the site. How can i accomplish this? I can probably create a php file that outputs something like:

<style type="text/css">
body{
    font-family: <?php echo get_option('my-font');?>;
}
</style>

and include that file in header.php, but that means that I have to hit php for every request for this css and I want to avoid that if posssible.

+1  A: 

Actually, I'd recommend placing that code directly in your header.php file. You'll already be parsing PHP code, so there's no reason you can't parse that get_option() request at the same time. I've used a similar system to generate a random header image on each page load based on WordPress options before as well.

EAMann
Yes, you are probably right. The problem is if I want to expand this with more custom css, the rendered html might become a litte verbose. But for now it's a good solution, thanks.
windyjonas
A: 

For one theme I built, there were CSS options aplenty, so I decided to generate static CSS files when the user made changes. To get around caching, I would store the timestamp of the last update, and echo it out as a parameter in the CSS URL;

<link rel="stylesheet" type="text/css" href="/path/to/generated/css.css?ver=<?php form_option('theme_name_css_timestamp'); ?>" />
TheDeadMedic