• Hi

    I am making a theme options page for my theme.

    I would like to have style options like change color for fonts.. font size etc you know CSS options!

    I have setup the theme options but how can I get value in theme CSS file? or how can I create a dynamic CSS file?

    I checked few themes and they are putting this CSS code in header.. Is it good way?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I hope you don’t mean the code is altering the header file!

    I would store the values in the options table, then output the corresponding CSS to the header at runtime via the wp_head() call. This is done by hooking the ‘wp_head’ action and echoing out your CSS style block. This works well because CSS on the page overrides any included CSS files with the same directives.

    Thread Starter Rakesh Raja

    (@rakeshraja)

    Can you provide a sample code please? How to use wp_head ?

    Moderator bcworkz

    (@bcworkz)

    Assuming your options page has previously added a valid color value to the options table under the key ‘rak_body_color’, do something like:

    function rak_style_head() {
      $color = get_option('rak_body_color');
      echo "<style>body {color: $color;}</style>";
    }
    add_action('wp_head', 'rak_style_head');

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Use CSS value from theme style options page?’ is closed to new replies.