开发者

How can I set the main theme-font dynamically, in WordPress

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 开发者_如何学Goinclude 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.


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.


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'); ?>" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜