Last active
May 2, 2018 04:27
-
-
Save proframework/70fbf836b4254175429e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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