Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Generate the CSS in the <head> section using the Theme Customizer
* @since 0.1
*/
add_action('generate_head_css','generate_your_css');
if ( !function_exists( 'generate_your_css' ) ) :
function generate_advanced_css()
{
$your_option = get_option( 'your_saved_db_entry' );
$space = ' ';
// Start the magic
$your_css = array (
// Header
'.site-header' => array(
'background' => $your_option['header_background_color'],
'color' => $your_option['header_text_color']
),
'.some-element' => array(
'background-image' => YOUR VALUE
)
);
// Output the above CSS
$output = '';
foreach($your_css as $k => $properties) {
if(!count($properties))
continue;
$temporary_output = $k . ' {';
$elements_added = 0;
foreach($properties as $p => $v) {
if(empty($v))
continue;
$elements_added++;
$temporary_output .= $p . ': ' . $v . '; ';
}
$temporary_output .= "}";
if($elements_added > 0)
$output .= $temporary_output;
}
$output = str_replace(array("\r", "\n"), '', $output);
echo $output;
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment