[theme-reviewers] Best practice CSS options
Chip Bennett
chip at chipbennett.net
Sat May 7 13:10:08 UTC 2011
If you're primarily changing colors, Theme settings should be very easy to
implement.
I would just enqueue a function that outputs all of the custom CSS at
wp_print_styles, e.g.:
<?php
function mytheme_custom_css() {
$mytheme_options = get_option( 'theme_mytheme_options' ); ?>
<script type="text/css">
#header {
color: #<?php echo $mytheme_options['header_text_color']; ?>;
}
</script>
<?php }
add_action( 'wp_print_styles', 'mytheme_custom_css' );
Validating/sanitizing hex color values is really simple, too. For each
setting, in your register_setting() validation callback, simply filter out
anything that is longer than 6 characters, and anything that has characters
other than 0-9a-f.
Chip
On Sat, May 7, 2011 at 6:59 AM, Tony Crockford <tonyc at boldfish.co.uk> wrote:
> Not sure if this is the appropriate place to ask, but it feels like I might
> get a good set of opinions, so here goes.
>
> What would be the best way to implement a style options admin area for a
> theme - e.g. so that a specific set of CSS values, could be easily changed
> by non technical users.
>
> Things like header text color, box border colors, box background colors
> etc.
>
> Every theme I look at does it differently and some respected theme authors
> say it shouldn't be an option, but that the CSS files should be edited (I
> think I agree, but have a client requirement for an easily changeable
> theme).
>
> I'm concerned about performance issues, is there a way to have an options
> panel write out a CSS file that is then used, instead of having to get
> over-ride values from the database and dropping them into the header.
>
> TIA for any help.
>
>
>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110507/591c28cc/attachment.htm>
More information about the theme-reviewers
mailing list