Home / Admin / Add Theme colors to Head
Duplicate Snippet

Embed Snippet on Your Site

Add Theme colors to Head

Gets the theme colors for X/Pro theme and adds them to the head location to use in :root as variables

<10
Code Preview
php
<?php
$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'] . '; } ';
  }
  $css .= '</style>';
  function colors_css() {
    global $css;
    echo $css;
  }
  add_action('wp_head', 'colors_css');
}

Comments

Add a Comment