您使用的代码有点脏:这里不需要foreach,我想您忘记了打印标题颜色(请参阅下面代码中的注释)。
之后,如果没有自定义项,则不想打印任何内容,请创建一个out变量,而不是空白打印样式:
add_action(\'wp_head\', \'dynamic_options\');
function dynamic_options() {
$checkbox = (array) get_option(\'sandbox_theme_social_options\');
if ( ! isset($checkbox[\'hide_sidebar\']) ) $checkbox[\'hide_sidebar\'] = \'off\';
$css = array(
\'headercolor\' => get_header_textcolor() ? : \'blank\',
\'wrapper_background_color\' => get_option(\'wrapper_background_color\') ? : \'blank\'
);
$out = \'\';
if( $css[\'wrapper_background_color\'] != \'blank\')
$out .= \'#wrapper { background-color:"\' . $css[\'wrapper_background_color\'] . \'"; }\';
// I think you forgot following 2 lines in your code ;)
if( $css[\'headercolor\'] != \'blank\')
$out .= \'#header { color: "\' . $css[\'headercolor\'] . \'"; }\';
if ( $checkbox[\'hide_sidebar\'] == \'on\' )
$out .= \'.sidebar_sec { display:none; }\';
if ( $out != \'\') echo \'<style type="text/css">\' . $out . \'</style>\';
}