Two questions from a coding ub3r n00b…
Firstly, I’m using the Options Framework Theme by Devin Price and just wanting to know how would I output the background property in the <head> section of my header.php file, from the Theme Options page only if the user has uploaded an image or chosen a color for this?
My options.php:
$options[] = array(
'name' => __('Background', 'options_framework_theme'),
'desc' => __('Add a background.', 'options_framework_theme'),
'id' => 'background-one',
'std' => $background_defaults,
'type' => 'background' );
My Theme Options page:

My header.php:
<style type="text/css">
<?php $background = of_get_option('background-one');
echo 'body {';
if ($background['color']) {
echo '
background: ' .$background['color']. ';';
}
if ($background['image']) {
echo '
background: url('.$background['image']. ') ';
echo ''.$background['repeat']. ' ';
echo ''.$background['position']. ' ';
echo ''.$background['attachment']. ';';
}
echo '
}';
?>
</style>
Which works perfectly fine in the front-end of my site, displaying the CSS as:
body {
background: #8224e3;
background: url(images/bg03.gif) repeat top left fixed;
}
But if the user hasn’t chosen a colour or image as a background through the Theme Options page, the source code will output:
body {
}
How would I be able to remove the above CSS if the user hasn’t chosen a background?
From what I gather, an if statement needs to be created but I don’t how to write this up correctly as I’m fairly new to php.
Secondly, how would I be able to set a default background image in the framework?
My options.php:
// Background Defaults
$background_defaults = array(
'color' => '',
'image' => '',
'repeat' => 'no-repeat',
'position' => 'top left',
'attachment' => 'fixed' );
Thanks
Just move a few things to be within an if statement, like so:
And, for your second question, simply make the following change: