WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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">
    <?php } ?>
share|improve this question
up vote 0 down vote accepted

Just put your dynamic CSS inside of a callback function, hooked into wp_print_script, e.g.

function mytheme_custom_css() {
    <script type="text/css">
    <?php if ( of_get_option('show_post_sidebar', true ) ) { ?>
    <?php } ?>
add_action( 'wp_print_scripts', 'mytheme_custom_css' );

Add as few, or as many, conditional CSS rules as you need.

share|improve this answer
Thanks for this, maybe I'm having a slow day, but how would I implement this only if someone chose the "left" option? – Dean Elliott Oct 27 '11 at 13:27
Just change if ( of_get_option('show_post_sidebar', true ) ) to whatever, as appropriate. Without knowing your options structure, I can't answer any more precisely. – Chip Bennett Oct 27 '11 at 13:54

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.

share|improve this answer
Unfortunately this needs to be hardcoded as it is for a theme that is going on general release – Dean Elliott Oct 27 '11 at 13:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.