How can I display a different style snippet if a user selects and option from my theme options page select box.
For example. To show the sidebar on the right a user would select “Right” and the default stylesheet would be used. However, if they chose “Left” to display it on the left, a small style snippet would appear that overrides the default stylesheet.
This is how I do it for checkboxes if that helps.
<?php if ( of_get_option('show_post_sidebar', false ) ) { ?>
<!-- default styles would be used -->
<?php } else {?>
<style type="text/css" media="screen">
.post{width:720px}
</style>
<?php } ?>
Just put your dynamic CSS inside of a callback function, hooked into
wp_print_script
, e.g.Add as few, or as many, conditional CSS rules as you need.
I myself have been researching this for my personal blog. There seem to be a few plugins if you’re not opposed to using one.
Edit:
WordPress appears to have a built-in function for this.
Edit again:
I’m sorry but I think I mis-read your question. I assumed that you were looking for a way to change themes based on user preference. I guess I should have read more carefully rather than skimming quickly.