Modify CSS via Theme Control Panel

From the looks of it your adding php right in the css which will not work. You need to write to the css file itself or dump it right into the html as Jeremy said as I am writing this:)

Writing a new CSS file every time you make any changes can tax your system, but works well if your not making lots of dynamic changes to a live site, for instance the twentyten weaver theme does this.

An easy way to do this is to actually turn your .css file into a .php file with the following at the top, and your php/css after.

header('Content-Type: text/css');

The alternative it to write it in the header of your html, lots of plugins do this, and it can be annoying to alter the markup since it is not semantically separate, but it’s also very easy.

Typically this is done using the Options API : http://codex.wordpress.org/Options_API

Here is an example that has used add_option in the backend for the background color (this is put in the header.php for example).

body {
  background-color: <?php echo get_option('background_color'); ?>;

For previews you can hook into the default preview_post_link and use an iframe, here is an example.

 <iframe src="https://wordpress.stackexchange.com/questions/12627/<?php echo clean_url(apply_filters("preview_post_link', add_query_arg('preview', 'true', get_permalink($post->ID)))); ?>" width="100%" height="600" ></iframe>

Please remember there are performance issues when writing dynamic styles and you should do more research into this topic depending on the context.

Leave a Comment