Last active
February 25, 2019 23:19
-
-
Save michaelbourne/f79dc2e8ea08bcc1c8231d005e843140 to your computer and use it in GitHub Desktop.
How to use Themeco Pro template colors anywhere on your site
This file contains hidden or 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
/** | |
* Get theme colors from Pro and turn them into classes and CSS variables | |
* Author: Michael Bourne | |
*/ | |
$themecolors = get_option('cornerstone_color_items'); | |
if($themecolors) { | |
$css = '<style type="text/css" id="themecolours">'; | |
$colors = json_decode( stripslashes( $themecolors ), true ); | |
$count = count($colors); | |
for($i = 0; $i <= $count-1; $i++){ | |
$name = 'xtt-' . preg_replace('/[^a-z0-9]/', "", strtolower($colors[$i]['title'])); | |
$css .= ':root { --' . $name . ': ' . $colors[$i]['value'] . '; } '; | |
$css .= '.' . $name . ' { color: ' . $colors[$i]['value'] . '; } '; | |
// you may need to add an !important to the rule to override X settings, like so: | |
// $css .= '.' . $name . ' { color: ' . $colors[$i]['value'] . '!important; } '; | |
} | |
$css .= '</style>'; | |
function colors_css() { | |
global $css; | |
echo $css; | |
} | |
add_action('wp_head', 'colors_css'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment