Skip to content

Instantly share code, notes, and snippets.

@proframework
Last active May 2, 2018 04:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proframework/70fbf836b4254175429e to your computer and use it in GitHub Desktop.
Save proframework/70fbf836b4254175429e to your computer and use it in GitHub Desktop.
<?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