The following snippet will let you have CSS minified in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <?php require('../../../wp-load.php'); function colorize($m){ // Your code to get the new color goes here, in this case it's grabbing a stored value from a Wordpress plugin. $c=get_option('tc_'.$m[4]); $m[3] = $c; if($c!=''){ return $c; }else{ return $m[0]; } } header("Content-type: text/css"); $css = file_get_contents('style.css'); $css = preg_replace('~/\*.*\*/|\n|\t|(?<=:)\s+|(?<={)\s+|(?<=})\s+|(?<=,)\s+|\s+(?=;)|\s+(?={)|\s+(?=})|\s+(?<=:)~sU','',preg_replace_callback('~((transparent|#[A-F0-9a-f]{6}))(?=(.)+(?=/\*#(.+)#\*/))~U','colorize',$css)); echo $css; ?> // example of the css before colorization, note the comment element { padding: 0; margin: 0 10px; color: #000000;/*#c_t#*/ } // how it looks after colorization, note the color. element { padding: 0; margin: 0 10px; color: #FF0000; } // older version, doesn't grab color codes as well, missing transparent keyword. <?php function colorize($v){ //whatever code you use to turn variable $v into color $c, very dependent on your specific implementation. return $c; } header("Content-type: text/css"); $css = file_get_contents('style.css'); $css = preg_replace('~/\*.*\*/|\n|\t|(?<=:)\s+|(?<={)\s+|(?<=})\s+|(?<=,)\s+|\s+(?=;)|\s+(?={)|\s+(?=})~sU','',preg_replace_callback('~#[A-F0-9a-f]{3,8}(?=;/\*#([\d\w\s]+)(:(.+))?#\*/)~U','colorize',$css)); echo $css; ?> |
Snippet Source/Credit: fatfolderdesign.com